コード例 #1
0
        public HttpResponseMessage addupFromApp(HttpRequestMessage request)
        {
            HttpContent           requestContent = Request.Content;
            string                jsonContent    = requestContent.ReadAsStringAsync().Result;
            PhieuSangLocViewModel phieuSangLocVm = JsonConvert.DeserializeObject <PhieuSangLocViewModel>(jsonContent);

            var userName = HttpContext.Current.GetOwinContext().Authentication.User.Identity.Name;
            var user     = userManager.FindByNameAsync(userName).Result;

            if (phieuSangLocVm.MaTrungTam != user.LevelCode && !phieuSangLocVm.IDPhieu.Contains(user.LevelCode))
            {
                return(request.CreateResponse(HttpStatusCode.ExpectationFailed, "Phiếu " + phieuSangLocVm.IDPhieu + "không thuộc trung tâm " + user.LevelCode));
            }

            HttpResponseMessage response = null;

            var phieuDB = phieuSangLocService.GetById(phieuSangLocVm.IDPhieu);

            if (phieuDB == null)
            {
                var newPhieu = new PhieuSangLoc();
                newPhieu.UpdatePhieuSangLoc(phieuSangLocVm);

                var lvcode = user.LevelCode;
                newPhieu.IDNhanVienTaoPhieu = user.Id;
                var newPatient = new Patient();
                newPatient.UpdatePatient(phieuSangLocVm);
                newPhieu.MaBenhNhan   = lvcode[1] + lvcode[2] + Guid.NewGuid().ToString();
                newPatient.MaBenhNhan = newPhieu.MaBenhNhan;
                phieuSangLocService.Add(newPhieu);
                patientService.Add(newPatient);
                phieuSangLocService.Save();
                response = request.CreateResponse(HttpStatusCode.Created, phieuSangLocVm);
            }
            else
            {
                phieuDB.UpdatePhieuSangLoc(phieuSangLocVm);
                var patientDB = patientService.GetByMaBN(phieuSangLocVm.MaBenhNhan);
                patientDB.UpdatePatient(phieuSangLocVm);

                this.phieuSangLocService.Update(phieuDB);
                this.patientService.Update(patientDB);
                donViCoSoService.Save();

                response = request.CreateResponse(HttpStatusCode.OK);
            }
            return(response);
        }
コード例 #2
0
        public HttpResponseMessage Create(HttpRequestMessage request, PhieuSangLocViewModel phieuSangLocVm)
        {
            var userName = HttpContext.Current.GetOwinContext().Authentication.User.Identity.Name;
            var user     = userManager.FindByNameAsync(userName).Result;

            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var phieuDB = phieuSangLocService.GetById(phieuSangLocVm.IDPhieu);
                    if (phieuDB != null)
                    {
                        phieuDB.UpdatePhieuSangLoc(phieuSangLocVm);
                        var patientDB = patientService.GetByMaBN(phieuSangLocVm.MaBenhNhan);
                        patientDB.UpdatePatient(phieuSangLocVm);

                        this.phieuSangLocService.Update(phieuDB);
                        this.patientService.Update(patientDB);
                        donViCoSoService.Save();

                        response = request.CreateResponse(HttpStatusCode.OK);
                    }
                    else
                    {
                        var newPhieu = new PhieuSangLoc();
                        newPhieu.UpdatePhieuSangLoc(phieuSangLocVm);
                        var lvcode = user.LevelCode;
                        newPhieu.IDNhanVienTaoPhieu = user.Id;
                        var newPatient = new Patient();
                        newPatient.UpdatePatient(phieuSangLocVm);
                        newPhieu.MaBenhNhan = lvcode[1] + lvcode[2] + Guid.NewGuid().ToString();
                        newPatient.MaBenhNhan = newPhieu.MaBenhNhan;
                        phieuSangLocService.Add(newPhieu);
                        patientService.Add(newPatient);
                        phieuSangLocService.Save();
                        response = request.CreateResponse(HttpStatusCode.Created, phieuSangLocVm);
                    }
                }

                return response;
            }));
        }