代码之家  ›  专栏  ›  技术社区  ›  ZIADIA Oussama

添加后显示id

  •  0
  • ZIADIA Oussama  · 技术社区  · 7 年前

    我想做的是在添加 这是我的服务

      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);
        });
    
    }
    

    知道怎么做吗?谢谢你的帮助

    1 回复  |  直到 7 年前
        1
  •  0
  •   Ahmado    7 年前

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

    public IHttpActionResult AddConsultation(yourModel consultation)
        {
    
                try
                {
                  int i =  consultationServices.Insert(consultation);
                    return Ok(i);
    
                }
                catch (Exception e)
                {
                    return InternalServerError();
                }
        }
    

    还有你的咨询服务。发布(此模型)如下所示:

        postconsultation(model: Consultation): Promise<number>
       {       
        return this.http.post("ApiUrl",model).toPromise()
       .then(response => response).catch(this.handleError);
       }