添加后显示ID

问题描述 投票:0回答:1

我想要做的是在添加这里后获取id是我的服务

  public int  Insert<T>(T model)
    {
        var consultation = Mapper.Map<T, Consultation>(model);

        consultationRepository.Insert(consultation);
        return consultation.id;  
    }

插入后我在我的服务中找回Id值,我只想在我的组件中获取该ID,以便我可以在添加后立即显示它 这是我的组件,

onSubmit(): void {

    swal({
        title: 'Are you sure?',
        text: "You won't be able to revert this!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, add it!'
    }).then(() => {
        this.model.DossierId = this.DossierId;
        this.model.DoctorId = this.DoctorId;
        this._consultationservice.post(this.model);
    });

}

任何想法如何做到这一点?并感谢您的帮助

angular asp.net-web-api
1个回答
0
投票

你必须在控制器api中使用你的方法

public IHttpActionResult AddConsultation(yourModel consultation)
    {

            try
            {
              int i =  consultationServices.Insert(consultation);
                return Ok(i);

            }
            catch (Exception e)
            {
                return InternalServerError();
            }
    }

并为您的咨询服务.post(this.model)这样的事情:

    postconsultation(model: Consultation): Promise<number>
   {       
    return this.http.post("ApiUrl",model).toPromise()
   .then(response => response).catch(this.handleError);
   }    
© www.soinside.com 2019 - 2024. All rights reserved.