예제 #1
0
        public HttpResponseMessage Create(HttpRequestMessage request, DanhMucDonViCoSoViewModel donviVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    if (donviVm.isLocked == null)
                    {
                        donviVm.isLocked = false;
                    }
                    var newDonVi = new DanhMucDonViCoSo();
                    newDonVi.UpdateDonViCoSo(donviVm);
                    donViCoSoService.Add(newDonVi);
                    donViCoSoService.Save();


                    var gdv = goidvtheotrungtamService.getAllTheoMaTT(newDonVi.MaDVCS.Substring(0, 3));
                    var gdvdvcs = Mapper.Map <IEnumerable <DanhMucGoiDichVuTrungTam>, IEnumerable <DanhMucGoiDichVuChung> >(gdv);

                    goidvtheodvcsService.Add(newDonVi.MaDVCS, gdvdvcs.ToList());
                    goidvtheodvcsService.Save();
                    var responseData = Mapper.Map <DanhMucDonViCoSo, DanhMucDonViCoSoViewModel>(newDonVi);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
예제 #2
0
        public HttpResponseMessage Create(HttpRequestMessage request, DanhMucDonViCoSoViewModel donviVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    if (donviVm.isLocked == null)
                    {
                        donviVm.isLocked = false;
                    }
                    var newDonVi = new DanhMucDonViCoSo();
                    newDonVi.UpdateDonViCoSo(donviVm);
                    donViCoSoService.Add(newDonVi);
                    donViCoSoService.Save();

                    var responseData = Mapper.Map <DanhMucDonViCoSo, DanhMucDonViCoSoViewModel>(newDonVi);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }