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; })); }
public HttpResponseMessage AddUppFromApp(HttpRequestMessage request) { HttpContent requestContent = Request.Content; string jsonContent = requestContent.ReadAsStringAsync().Result; DanhMucGoiDichVuDVCS goidvdvcsVm = JsonConvert.DeserializeObject <DanhMucGoiDichVuDVCS>(jsonContent); var userName = HttpContext.Current.GetOwinContext().Authentication.User.Identity.Name; var user = userManager.FindByNameAsync(userName).Result; if (goidvdvcsVm.MaDVCS.Contains(user.LevelCode)) { var term = goiDichVuDVCSService.GetSingle(goidvdvcsVm.MaDVCS, goidvdvcsVm.IDGoiDichVuChung); if (term == null) { goiDichVuDVCSService.Add(goidvdvcsVm); } else { var rowId = term.RowIDGoiDichVuTrungTam; term = goidvdvcsVm; term.RowIDGoiDichVuTrungTam = rowId; goiDichVuDVCSService.Update(term); } goiDichVuDVCSService.Save(); return(request.CreateResponse(HttpStatusCode.OK)); } else { return(request.CreateResponse(HttpStatusCode.NotAcceptable, "Không có quyền sửa hoặc update " + goidvdvcsVm.MaDVCS)); } }