Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "michaelhilgers"

Angular2 - asp core

Hi,

I'd like using the dropdown from keenthemes like the first one here <a class="postlink" href="http://keenthemes.com/preview/metronic/theme/admin_4_angularjs/index.html#/ui_select.html">http://keenthemes.com/preview/metronic/ ... elect.html</a>

I included the select2 version 4.0.3 in the package.json. Then I added the select2.js and the select2.css in the angular-cli.json

So if I'm in my modals html I try to use it like this:

<div class="form-group">
                                        <label class="control-label col-md-3">Small</label>
                                        <div class="col-md-4">
                                            <select id="selectPreview" class="form-control select2me select2-bootstrap-prepend" data-placeholder="Select...">
                                                <option value=""></option>
                                                <option value="AL">Alabama</option>
                                                <option value="WY">Wyoming</option>
                                            </select>
                                            <span class="help-block">
                                                .input-small
                                            </span>
                                        </div>
                                    </div>

if I try to call in the modal ts file in the afterViewInit the

$('#selectPreview').select2
({
      placeholder: "Select",
      width: 'auto', 
      allowClear: true
   });
});

It doesn't know the select2 in jQuery

Could you help me please ?

Answer

Yes, I solved the problem.

Question

Hi,

I have the following template inside a *ngFor. I have a detailList with details.

Inside the template there are 3 select boxes. To fill the select boxes I need 3 different List. - documentList

  • aktivitaetenList
  • dokumentPositionDetailList

To get those lists I called multiple services. But if I selected a value in the "dokument" <select> I need to filter the aktivitaetenList and the documentPositionDetailFilteredList

I saved the filtered lists in different variables:

  • filteredAktivitaetenList = filtered aktivitaetenList
  • documentPositionDetailFilteredList = filtered dokumentPositionDetailList

Now for the first element inside my "detailList" all works fine. I select a document => the aktivitaetList was filtered and shows only the aktivtaeten for the document it works also for the dokumentPositionDetailList.

BUT when I add know a new element inside my "detailList" and I want to select an aktivitaet without select a document (it should be filled with aktivities) there is only the filtered list from the previous detail.

How can I achieve to get the complete list of activities inside each detail of detailList ?(detail 1, detail 2 ,....).

Thanks for help me !

<div class="panel panel-default" *ngFor="let detail of detailList; let index = index;let first = first;let last = last;">
        <form #accordionForm="ngForm" novalidate>
            <div class="panel-heading" role="tab" id="heading{{index}}">
                <div class="panel-title">
                    <a role="button" name="collapseHead{{index}}" data-toggle="collapse" data-parent="#accordion" href="#colapse{{index}}" aria-expanded="false">
                    </a>                    
                </div>
            </div>
            <div id="colapse{{index}}" class="panel-collapse collapse" [ngClass]="{'in': last}" role="tabpanel">
                <div class="panel-body">
                    <div *ngIf="detail.aktivitaet === undefined || (detail.aktivitaet !== undefined && detail.aktivitaet !== null && detail.aktivitaet.dokumentErlaubtJN)" class="form-group form-md-line-input form-md-floating-label no-hint">
                        <label>{{l("Dokument")}}</label>
                        <select name="dokument{{index}}" class="form-control" (change)="getFilteredAktivitaeten(index, detail.dokumenteId )" [ngClass]="{'edited': detail.dokumenteId }" [(ngModel)]="detail.dokumenteId">
                            <option [ngValue]="undefined" selected>{{l('NoDokumentSelected')}}</option>
                            <option *ngFor="let dokument of documentList;" [ngValue]="document.id">{{dokument.bezeichnungDE}}</option>
                        </select>
                    </div>
                    <div class="form-group form-md-line-input form-md-floating-label no-hint">
                        <label>{{l("Aktivitaet")}}</label>
                        <select name="aktivitaetId{{index}}" class="form-control" [ngClass]="{'edited': detail.aktivitaetId }" (change)="setAktivitaet(index);" [(ngModel)]="detail.aktivitaetId" required>
                            <option [ngValue]="undefined" selected>{{l('SelectAktivitaet')}}</option>
                            <option *ngFor="let aktivitaet of filteredAktivitaetenList;" [ngValue]="aktivitaet.id">{{aktivitaet.bezeichnungDE}}</option>
                        </select>
                    </div>
                    <div *ngIf="detail.dokumenteId" class="form-group form-md-line-input form-md-floating-label no-hint">
                        <label>{{l("DokumentPositionDetail")}}</label>
                        <select name="dokumentPositionDetail{{index}}" class="form-control" [ngClass]="{'edited': detail.dokumentPositionDetailId }" [(ngModel)]="detail.dokumentPositionDetailId" [required]="detail.dokumentPositionDetailId">
                            <option [ngValue]="undefined" selected>{{l('NoDokumentDetailSelected')}}</option>
                            <option *ngFor="let dokumentDetail of documentPositionDetailFilteredList;" [ngValue]="dokumentDetail.id">{{dokumentDetail.id}}</option>
                        </select>
                    </div>                    
                </div>
            </div>
        </form>
    </div>
@Component({
    selector: 'createUpdateArbeitstagDetail',
    templateUrl: './create-update-arbeitstagDetail.component.html'
})
export class CreateUpdateArbeitstagDetailComponent extends AppComponentBase implements AfterViewInit {

    @Input() detailList: Array<detailListeDto>;

    @Output() detailListChanged: EventEmitter<Array<detailListeListDto>> = new EventEmitter<Array<detailListeDto>>();

    aktivitaetenList: AktivitaetListDto[];
    dokumentList: DokumentListDto[];
    dokumentPositionDetailList: DokumentPositionDetailListDto[];
    dokumentPositionDetailFilteredList: DokumentPositionDetailListDto[];
    filteredAktivitaetenList: AktivitaetListDto[];


    constructor(injector: Injector,
        private _aktivitaetService: AktivitaetServiceProxy,
        private _dokumentService: DokumentServiceProxy
    ) {
        super(injector);
		
        this.aktivitaetenList = new Array<AktivitaetListDto>();
        this.dokumentList = new Array<DokumentListDto>();
        this.dokumentPositionDetailList = new Array<DokumentPositionDetailListDto>();
        this.filteredAktivitaetenList = new Array<AktivitaetListDto>();
    }

    ngAfterViewInit(): void {
        var self = this;

        this._dokumentService.getAllDokumentAsync().subscribe(response => {
            this.dokumentList = response.items;
        });

        this._dokumentService.getDokumentPositionenDetail().subscribe(response => {
            this.dokumentPositionDetailList = response.items;
        });

        this._aktivitaetService.getAllAktivitaetenAsync().subscribe(response => {
            this.aktivitaetenList = response.items;
        });
    }

    getFilteredAktivitaeten(index: number, dokumentId?: number): void {
		
		// If a document was selected I call the service to get all aktivities for the current selected document
        if (dokumentId) {
            this._aktivitaetService.getAllAktivitaetenForDokument(dokumentId).subscribe(response => {
                this.filteredAktivitaetenList = response.items;
            });

			// Load the details for the document
            this.getDokumentDetails(dokumentId);
        }
        else {
			// Load all activities without a document
            this.filteredAktivitaetenList = this.aktivitaetenList.filter(x => x.dokumentPflichtJN === false);
        }
    }

    getDokumentDetails(dokumentId?: number): void {
        this.dokumentPositionDetailFilteredList = this.dokumentPositionDetailList.filter(x => x.dokumentId == dokumentId);
    }     

    delete(index: number): void {
        this.message.confirm(
            this.l('AreYouSureToDeleteTheDetail', this.detailList[index].aktivitaet),
            isConfirmed => {
                if (isConfirmed) {
                    this.detailList.splice(index, 1);

                    this.detailListChanged.emit(this.detailList);
                }
            }
        )
    };
}

Hi,

I created a service with an whose has got a function with a class as input.

public async Task<ListResultDto<ArbeitszeitListDto>> GetArbeitszeitenAsync(ArbeitszeitenInputDto input)
        {
                  
        }

The input class "ArbeitszeitenInputDto" looks like

public class ArbeitszeitenInputDto
    {
       
        public int? MitarbeiterId { get; set; }

       
        public int? MaschineId { get; set; }

       
        public string Filter { get; set; }
       
        [Required]
        public DateTime StartDatum { get; set; }
       
        [Required]
        public DateTime EndDatum { get; set; }
    }

But only for this class, nswag doesn't gernerate a class. For all the other classes I created it worked fine.

=> Angular2 => service-proxies.ts generated code:

/**
     * @return Success
     */
    getArbeitszeitenAsync(mitarbeiterId: number, maschineId: number, filter: string, startDatum: moment.Moment, endDatum: moment.Moment): Observable<ListResultDtoOfArbeitszeitListDto> {
        let url_ = this.baseUrl + "/api/services/app/Arbeitszeit/GetArbeitszeitenAsync?";
        if (mitarbeiterId !== undefined)
        
            url_ += "MitarbeiterId=" + encodeURIComponent("" + mitarbeiterId) + "&"; 
        
        if (maschineId !== undefined)
        
            url_ += "MaschineId=" + encodeURIComponent("" + maschineId) + "&"; 
        
        if (filter !== undefined)
        
            url_ += "Filter=" + encodeURIComponent("" + filter) + "&"; 
        
        if (startDatum !== undefined)
        
            url_ += "StartDatum=" + encodeURIComponent("" + startDatum.toJSON()) + "&"; 
        
        if (endDatum !== undefined)
        
            url_ += "EndDatum=" + encodeURIComponent("" + endDatum.toJSON()) + "&";

        const content_ = "";
        
        return this.http.request(url_, {
            body: content_,
            method: "get",
            headers: new Headers({
                "Content-Type": "application/json; charset=UTF-8", 
				"Accept": "application/json; charset=UTF-8"
            })
        }).map((response) => {
            return this.processGetArbeitszeitenAsync(response);
        }).catch((response: any, caught: any) => {
            if (response instanceof Response) {
                try {
                    return Observable.of(this.processGetArbeitszeitenAsync(response));
                } catch (e) {
                    return <Observable<ListResultDtoOfArbeitszeitListDto>><any>Observable.throw(e);
                }
            } else
                return <Observable<ListResultDtoOfArbeitszeitListDto>><any>Observable.throw(response);
        });
    }

Is there somewhere a mistake or why didn't the nswag generate a class from it ?

Greatings,

Hi,

I ran into an issue when I try to get the token from the TokenAuthController.

I use in my test project the TestServer from the Microsoft.AspNetCore.TestHost Assembly.

I tested my WebApi without the code below to get the Token and all worked fine. After the test I will get a Token to test other function so I implemented the following code:

I created an BaseWebApiClient class an into this class I 'll get the token.

string path = $"/api/TokenAuth/Authenticate";

            AjaxResponse<AuthenticateResultModel> result = new AjaxResponse<AuthenticateResultModel>();

            try
            {
                Client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                var serializedString = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(input), Encoding.UTF8, "application/json");

                // Achtung hier funktioniert nur PostAsync und keine PostAsync as Json oder sonstwas
                HttpResponseMessage response = await Client.PostAsync(path, serializedString);

                var json = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                    result = Newtonsoft.Json.JsonConvert.DeserializeObject<AjaxResponse<AuthenticateResultModel>>(json);
                else
                    result = new AjaxResponse<AuthenticateResultModel>(Newtonsoft.Json.JsonConvert.DeserializeObject<AjaxResponse<ErrorInfo>>(json).Error);
            }
            catch (Exception e)
            {
                result = new AjaxResponse<AuthenticateResultModel>(new ErrorInfo(e.HResult, e.Message));
            }

            // Token setzen 
            if (result.Success)
            {
                Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.Result.AccessToken);
            }

When I try now to get the token in my Unittest I got multiple Errors:

The First Error was that "Microsoft.IdentityModel.Tokens" wasn't found in the test project => I added the package => work Next Error was that "System.IdentityModel.Tokens.Jwt": wasn't found in the Host.Core ( I added a Host.Core Project for the TestServer => same classes as in Host project ) => Added the package => work

Now I can debug the code in the BaseWebApi an here I got the following response

{Method: POST, RequestUri: 'http://localhost/api/TokenAuth/Authenticate', Version: 1.1, Content: System.Net.Http.StringContent, Headers: { Accept: application/json Accept: application/json Host: localhost Content-Type: application/json; charset=utf-8 }}

All other test passed but I m not able to get a token...

Can you help me please ?

Hi,

All unittests failed but I found the error...

The error was in the entity, it was an attribute on a property :roll: :

"[Column(TypeName = "NVARCHAR(Max)")]"

[Column(TypeName = "NVARCHAR(Max)")]
public string Name { get; set; }

Hi,

I created a custom table "CustomSettings". And integrated it in the DBContext in the EF project

[DbConfigurationType(typeof(PMDbConfiguration))]
    public class PMDbContext : AbpZeroDbContext<Tenant, Role, User>
    {
        /* Define an IDbSet for each entity of the application */

        public virtual IDbSet<BinaryObject> BinaryObjects { get; set; }

        public virtual IDbSet<Friendship> Friendships { get; set; }

        public virtual IDbSet<ChatMessage> ChatMessages { get; set; }

        public virtual IDbSet<CustomSetting.CustomSetting> CustomSettings { get; set; }

        public virtual IDbSet<Land.Land> Land { get; set; }
       
       // more custom tables

        /* Default constructor is needed for EF command line tool. */
        public PMDbContext()
            : base(GetConnectionString())
        {
        }

I creadted a migration file an updated the database all works fine.

But I debug the unittest local I got an error message:

"Sequence contains no matching element"

public PMDbContext(DbConnection dbConnection)
            : base(dbConnection, true)
        {

        }

If I commented out the new "IDBSet<CustomSettings>" table in the PMDBContext class the unittests run without errors.

I can see that the DbManager threw an System.InvalidOperationException

Hi,

The server runs in a 64-bit mode.

If I commented out the line in the project.json VS created an .dll instead of the .exe from the EntityFramework project, and with the .dll it works fine.

The problem is that the EF isn't an dll

Hi,

I found the error. I could’t create the migrations file because I commented out the line

"buildOptions": {
    //"emitEntryPoint": true
  },

And the

public class program
    {
        public static void Main()
        {

        }
    }

in the EntityFramework project.

I did that because if I ran the unittest on the build server without comment out the line I got an error :

2017-01-24T10:32:38.2725042Z ##[error]Error Message: 2017-01-24T10:32:38.2725042Z ##[error] System.BadImageFormatException : Could not load file or assembly 'LignaSystems.PM.EntityFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format. 2017-01-24T10:32:38.2725042Z ##[error]Stack Trace: 2017-01-24T10:32:38.2725042Z ##[error] at LignaSystems.PM.Tests.AppTestBase..ctor()

Do you have an solution for the problem ?

Unfortunately it isn't the error, I use the correct classname "public virtual IDbSet<CustomSettings.CustomSetting> CustomSettings { get; set; }" ( sorry I added an s when I pasted the code).

Can I try something to get you further information ?

Showing 21 to 30 of 41 entries