Base solution for your next web application

Activities of "bakinalp"

Hi Aaron thanks for the support.

Finally I can get a response when I create a record but the id field seems a bit odd. I am getting a negative number close to but not exactly int.MinValue . I think this is the temp id before record is saved to the db. İs this the expected behaviour?

using System;
using System.Linq;
using System.Linq.Dynamic.Core;
using Abp.Linq.Extensions;
using System.Collections.Generic;
using System.Threading.Tasks;
using Abp.Domain.Repositories;
using Procure.Procurement.Dtos;
using Abp.Application.Services.Dto;
using Procure.Authorization;
using Abp.Authorization;
using Microsoft.EntityFrameworkCore;

namespace Procure.Procurement
{
	[AbpAuthorize(AppPermissions.Pages_Procurement)]
    public class ProcurementAppService : ProcureAppServiceBase, IProcurementAppService
    {
		 private readonly IRepository<PEvent> _pEventRepository;

		  public ProcurementAppService(IRepository<PEvent> pEventRepository) 
		  {
			_pEventRepository = pEventRepository;
		  }

		 public async Task<PagedResultDto<PEventDto>> GetAll(GetAllPEventsInput input)
         {
            var query = _pEventRepository.GetAll().WhereIf(
                    !string.IsNullOrWhiteSpace(input.Filter),
                    e =>  e.Title.Contains(input.Filter) || e.Description.Contains(input.Filter) 
                );

            var totalCount = await query.CountAsync();

            var pEvents = await query
                .OrderBy(input.Sorting ?? "id asc")
                .PageBy(input)
                .ToListAsync();

            return new PagedResultDto<PEventDto>(
                totalCount,
                ObjectMapper.Map<List<PEventDto>>(pEvents)
            );
         }
		 
		 [AbpAuthorize(AppPermissions.Pages_Procurement_Edit)]
		 public async Task<CreateOrEditPEventDto> GetPEventForEdit(EntityDto<int> input)
         {
            var pEvent = await _pEventRepository.FirstOrDefaultAsync(input.Id);
            return ObjectMapper.Map<CreateOrEditPEventDto>(pEvent);
         }

		 public async Task CreateOrEdit(CreateOrEditPEventDto input)
         {
            if(input.Id == null){
				await Create(input);
			}
			else{
				await Update(input);
			}
         }

		 [AbpAuthorize(AppPermissions.Pages_Procurement_Create)]
		 private async Task Create(CreateOrEditPEventDto input)
         {
            var pEvent = ObjectMapper.Map<PEvent>(input);

			            if (AbpSession.TenantId != null)
            { 
 pEvent.TenantId =  (int) AbpSession.TenantId;
            }

            await _pEventRepository.InsertAsync(pEvent);
         }

		 [AbpAuthorize(AppPermissions.Pages_Procurement_Edit)]
		 private async Task Update(CreateOrEditPEventDto input)
         {
            var pEvent = await _pEventRepository.FirstOrDefaultAsync((int)input.Id);
             ObjectMapper.Map(input, pEvent);
         }

		 [AbpAuthorize(AppPermissions.Pages_Procurement_Delete)]
         public async Task Delete(EntityDto<int> input)
         {
            await _pEventRepository.DeleteAsync(input.Id);
         }
    }
}

Here is the code in ts.

import { Component, ViewChild, Injector, Output, EventEmitter} from '@angular/core';
import { ModalDirective } from 'ngx-bootstrap';
import { ProcurementServiceProxy, CreateOrEditPEventDto} from '@shared/service-proxies/service-proxies';
import { AppComponentBase } from '@shared/common/app-component-base';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/fromPromise';
import 'rxjs/add/operator/toPromise';

@Component({
    selector: 'createOrEditPEventModal',
    templateUrl: './create-or-edit-pEvent-modal.component.html'
})
export class CreateOrEditPEventModalComponent extends AppComponentBase {

    @ViewChild('createOrEditModal') modal: ModalDirective;

    @Output() modalSave: EventEmitter<any> = new EventEmitter<any>();

    active = false;
    saving = false;
   
    pEvent: CreateOrEditPEventDto = new CreateOrEditPEventDto();

    constructor(
        injector: Injector,
        private _procurementServiceProxy: ProcurementServiceProxy
    ) {
        super(injector);
    }

    ngOnInit(): void {
        
    }

    show(pEventId?: number): void {
        if (!pEventId) { 
			this.pEvent = new CreateOrEditPEventDto();
			this.pEvent.id = pEventId;
			this.active = true;
			this.modal.show();
        }
		else{
			this._procurementServiceProxy.getPEventForEdit(pEventId).subscribe(pEventResult => {
				this.pEvent = pEventResult;
				this.active = true;
				this.modal.show();
			});
        }
        
    }

    save(): void {
		/*	this.saving = true;
			this._procurementServiceProxy.createOrEdit(this.pEvent)
			 .finally(() => { this.saving = false; })
			 .subscribe(() => {
			    this.notify.info(this.l('SavedSuccessfully'));
				this.close();
				this.modalSave.emit(null);
                });
        */
        this._procurementServiceProxy.createOrEdit(this.pEvent)
            .finally(() => this.saving = false)
            .subscribe(event => {
                this.notify.info(this.l('SavedSuccessfully'));
                alert(event);                
            });
    }

    close(): void {
        this.active = false;
        this.modal.hide();
    }
}

post looks succesfull but response is null. Shall I look somewhere else? I am trying to achieve this on autogenerated edit-or-create-modal.ts

Thanks Aaron ,

after subscribe I have tried to check the event value using a simple alert but it shows null. The value is submitted to the database fine but still cant get the eventid. I'm probably missing something simple but no idea what.

alert(event); //returns null
        alert(event.Id); //returns null
        this.newEventProduct.EventId = event.Id;

Thank you aaron for your response I was away for a few days. ( my wife was in labor and I took a few days off :D ).

I have tested out the .then statement but it is throwing an error saying "then does not exist on type 'Observable <void>' "

I have imported import { Observable } from 'rxjs/Observable'; but this does not resolve the problem. Am I missing something?

Showing 1 to 6 of 6 entries