public JObject Create(TreatmentHistory treatmentHistory, string filmDocuments = "")
 {
     treatmentHistory.DateCreated = DateTime.UtcNow;
     treatmentHistory.DoctorId = User.UserId;
     _db.TreatmentHistories.Add(treatmentHistory);
     _db.SaveChanges();
     if (!string.IsNullOrEmpty(filmDocuments))
     {
         JArray filmDocumentsJson = JArray.Parse(filmDocuments) as JArray;
         foreach (dynamic filmDocumentJson in filmDocumentsJson)
         {
             var fileName = DateTime.Now.Ticks + ".png";
             var path = HttpContext.Server.MapPath("~/Content/Image/FilmDocument/" + fileName);
             string imgBase64 = filmDocumentJson.ImgBase64;
             filmDocumentBO.SaveFilmDocumentFromBase64String(imgBase64, path);
             FilmDocument filmDocument = new FilmDocument
             {
                 Conclusion = filmDocumentJson.Conclusion,
                 Description = filmDocumentJson.Description,
                 FilmTypeId = filmDocumentJson.FilmTypeId,
                 TreatmentHistoryId = treatmentHistory.TreatmentHistoryId,
                 ImagePath = fileName,
                 DoctorId = User.UserId,
                 DateCreated = DateTime.UtcNow
             };
             _db.FilmDocuments.Add(filmDocument);
         }
     }
     _db.SaveChanges();
     dynamic result = new JObject();
     result.result = "ok";
     return result;
 }
Ejemplo n.º 2
0
 private static void DisplayToGridRow(TreatmentHistory item, DataGridViewRow row)
 {
     row.Cells["Date"].Value      = item.DateTreated.ToString("dd MMM yyyy");
     row.Cells["Treatment"].Value = item.Treatment;
     row.Cells["Diagnosis"].Value = item.Condition;
     row.Tag = item;
 }
Ejemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            TreatmentHistory treatmentHistory = db.TreatmentHistories.Find(id);

            db.TreatmentHistories.Remove(treatmentHistory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public JObject Create(TreatmentHistory treatmentHistory)
 {
     _db.TreatmentHistories.Add(treatmentHistory);
     _db.SaveChanges();
     dynamic result = new JObject();
     result.result = "ok";
     return result;
 }
        public async Task InsertNewTreatmentAsync(TreatmentHistory treatment)
        {
            if (treatment == null)
            {
                throw new ArgumentNullException(nameof(treatment));
            }

            await _treatmentHistoryRepository.InsertAsync(treatment);
        }
 public ActionResult Create(int medicalProfileId)
 {
     var treatmentHistory = new TreatmentHistory
     {
         MedicalProfileId = medicalProfileId,
         OnSetDate = DateTime.Now,
         DateCreated = DateTime.Now
     };
     return PartialView("_Create", treatmentHistory);
 }
Ejemplo n.º 7
0
        public int AddTreatmentHistory(TreatmentHistory treatment)
        {
            var treatmentRepository = new BaseRepository <HR_TREATMENTHISTORY>(new CRDatabase());
            var maxId  = treatmentRepository.GetMaxId("HR_TREATMENTHISTORY", "ID");
            var entity = ModelToEntity(treatment);

            entity.TREATMENTHISTORYID = maxId.ToString();
            treatmentRepository.Insert(entity);
            return(maxId);
        }
Ejemplo n.º 8
0
 public ActionResult Edit([Bind(Include = "TreatmentHistoryId,UserId,StutusId,RequestId,LastUpdateBy,LastUpdateDate")] TreatmentHistory treatmentHistory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(treatmentHistory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.Users, "UserId", "FirstNameAr", treatmentHistory.UserId);
     return(View(treatmentHistory));
 }
 public ActionResult Create(int medicalProfileId)
 {
     var doctor = _db.Doctors.ToList();
     ViewBag.Doctor = doctor;
     var treatmentHistory = new TreatmentHistory
     {
         MedicalProfileId = medicalProfileId,
         OnSetDate = DateTime.Now,
         DateCreated = DateTime.Now
     };
     return PartialView("Create", treatmentHistory);
 }
Ejemplo n.º 10
0
        // GET: TreatmentHistories/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TreatmentHistory treatmentHistory = db.TreatmentHistories.Find(id);

            if (treatmentHistory == null)
            {
                return(HttpNotFound());
            }
            return(View(treatmentHistory));
        }
Ejemplo n.º 11
0
        // GET: TreatmentHistories/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TreatmentHistory treatmentHistory = db.TreatmentHistories.Find(id);

            if (treatmentHistory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserId = new SelectList(db.Users, "UserId", "FirstNameAr", treatmentHistory.UserId);
            return(View(treatmentHistory));
        }
 public static TreatmentHistoryDTO TreatmentHistoryToDTO(TreatmentHistory treatmentHistory)
 {
     return(new TreatmentHistoryDTO
     {
         Id = treatmentHistory.Id,
         Comment = treatmentHistory.Comment,
         DateOfTreatment = treatmentHistory.DateOfTreatment,
         Price = treatmentHistory.Price,
         MedicalChart = treatmentHistory.MedicalChart,
         Treatment = treatmentHistory.Treatment,
         Tooth = treatmentHistory.Tooth,
         User = treatmentHistory.User,
         Affiliate = treatmentHistory.Affiliate
     });
 }
Ejemplo n.º 13
0
        public async Task <IActionResult> CreatePatient()
        {
            Patient foundPatient = _db.Patient.Where(p => p.Pesel == Patient.Pesel).FirstOrDefault();

            if (foundPatient != null)
            {
                if (foundPatient.NotPatientAnymore)
                {
                    foundPatient.NotPatientAnymore = false;
                    await _db.SaveChangesAsync();

                    _flasher.Flash(Types.Info, "Pomyślnie dodano nowego pacjenta.", dismissable: true);;
                }
                else
                {
                    _flasher.Flash(Types.Danger, "Pacjent jest już zapisany w systemie.", dismissable: true);
                }
            }
            else if (!PeselChecksum(Patient.Pesel))
            {
                _flasher.Flash(Types.Danger, "Podany pesel jest nieprawidłowy.", dismissable: true);
            }
            else
            {
                Patient.DateCreated    = DateTime.Now;
                Patient.CurrenctDoctor = _db.User.Where(usr => usr.Pesel == User.FindFirstValue(ClaimTypes.NameIdentifier))
                                         .Select(x => x).First();
                Patient.RoentgenPhoto = RoentgenGenerator.LoadRandomImage();

                TreatmentHistory th = new TreatmentHistory
                {
                    Doctor        = Patient.CurrenctDoctor,
                    Patient       = Patient,
                    TreatmentDate = DateTime.Now
                };

                await _db.Patient.AddAsync(Patient);

                await _db.TreatmentHistory.AddAsync(th);

                await _db.SaveChangesAsync();

                _flasher.Flash(Types.Info, "Pomyślnie dodano nowego pacjenta.", dismissable: true);
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 14
0
 private TreatmentHistory EntityToModel2(HR_TREATMENTHISTORY entity)
 {
     if (entity != null)
     {
         var model = new TreatmentHistory()
         {
             TREATMENTHISTORYID  = entity.TREATMENTHISTORYID,
             DISEASEHISTORYID    = entity.DISEASEHISTORYID,
             TREATMENTTIME       = entity.TREATMENTTIME,
             TREATMENTHOSPITAL   = entity.TREATMENTHOSPITAL,
             TREATMENTTYPE       = entity.TREATMENTTYPE,
             OPERATIONTYPE       = entity.OPERATIONTYPE,
             OPERATIONRESLUT     = entity.OPERATIONRESLUT,
             RADIOTHERAPYDOSE    = entity.RADIOTHERAPYDOSE,
             RADIOTHERAPYRESLUT  = entity.RADIOTHERAPYRESLUT,
             CHEMOTHERAPYPROJECT = entity.CHEMOTHERAPYPROJECT,
             CHEMOTHERAPYDRUG    = entity.CHEMOTHERAPYDRUG,
             CHEMOTHERAPYRESLUT  = entity.CHEMOTHERAPYRESLUT
         };
         return(model);
     }
     return(null);
 }
Ejemplo n.º 15
0
 private HR_TREATMENTHISTORY ModelToEntity(TreatmentHistory model)
 {
     if (model != null)
     {
         var entity = new HR_TREATMENTHISTORY()
         {
             TREATMENTHISTORYID  = model.TREATMENTHISTORYID,
             DISEASEHISTORYID    = model.DISEASEHISTORYID,
             TREATMENTTIME       = model.TREATMENTTIME,
             TREATMENTHOSPITAL   = model.TREATMENTHOSPITAL,
             TREATMENTTYPE       = model.TREATMENTTYPE,
             OPERATIONTYPE       = model.OPERATIONTYPE,
             OPERATIONRESLUT     = model.OPERATIONRESLUT,
             RADIOTHERAPYDOSE    = model.RADIOTHERAPYDOSE,
             RADIOTHERAPYRESLUT  = model.RADIOTHERAPYRESLUT,
             CHEMOTHERAPYPROJECT = model.CHEMOTHERAPYPROJECT,
             CHEMOTHERAPYDRUG    = model.CHEMOTHERAPYDRUG,
             CHEMOTHERAPYRESLUT  = model.CHEMOTHERAPYRESLUT
         };
         return(entity);
     }
     return(null);
 }
Ejemplo n.º 16
0
        public ActionResult Treatment(FormCollection form, Treatment obj, string SubmitBtn, int tabindex)
        {
            try
            {
                ViewBag.tabindex = tabindex;
                int resetflag = 0;
                obj.CMD = SubmitBtn;

                obj.hid       = Convert.ToInt32(Session["hospital"]);
                obj.patientid = Convert.ToInt32(Session["PatientId"]);

                var doctorarr = form["doctor"].ToString().Split(':');
                obj.dfname = doctorarr[1];
                obj.dlname = doctorarr[2];



                //Medicines
                List <TreatmentMedicine> tm = new List <TreatmentMedicine>();
                if (Session["TreatmentMedicine"] != null)
                {
                    tm = (List <TreatmentMedicine>)Session["TreatmentMedicine"];
                }
                else
                {
                    tm = new List <TreatmentMedicine>();
                }

                //Complents
                List <TreatmentComplents> tc = new List <TreatmentComplents>();
                if (Session["TreatmentComplents"] != null)
                {
                    tc = (List <TreatmentComplents>)Session["TreatmentComplents"];
                }
                else
                {
                    tc = new List <TreatmentComplents>();
                }

                //Diagnosis
                List <TreatmentDiagnosis> td = new List <TreatmentDiagnosis>();
                if (Session["TreatmentDiagnosis"] != null)
                {
                    td = (List <TreatmentDiagnosis>)Session["TreatmentDiagnosis"];
                }
                else
                {
                    td = new List <TreatmentDiagnosis>();
                }

                //History
                List <TreatmentHistory> th = new List <TreatmentHistory>();
                if (Session["TreatmentHistory"] != null)
                {
                    th = (List <TreatmentHistory>)Session["TreatmentHistory"];
                }
                else
                {
                    th = new List <TreatmentHistory>();
                }

                //Checkup
                List <TreatmentCheckups> tch = new List <TreatmentCheckups>();
                if (Session["TreatmentCheckups"] != null)
                {
                    tch = (List <TreatmentCheckups>)Session["TreatmentCheckups"];
                }
                else
                {
                    tch = new List <TreatmentCheckups>();
                }

                //Fundus
                List <TreatmentFundus> tf = new List <TreatmentFundus>();
                if (Session["TreatmentFundus"] != null)
                {
                    tf = (List <TreatmentFundus>)Session["TreatmentFundus"];
                }
                else
                {
                    tf = new List <TreatmentFundus>();
                }

                //Advice
                List <TreatmentAdvice> ta = new List <TreatmentAdvice>();
                if (Session["TreatmentAdvice"] != null)
                {
                    ta = (List <TreatmentAdvice>)Session["TreatmentAdvice"];
                }
                else
                {
                    ta = new List <TreatmentAdvice>();
                }


                switch (SubmitBtn)
                {
                case "Continue":
                    TempData["CMD"] = SubmitBtn; return(RedirectToAction("Treatment", obj));

                case "addmedicine":
                    //Medicines
                    TreatmentMedicine t = new TreatmentMedicine();
                    t.a = obj.TreatMedicine.aischecked == true ? "A" : "";
                    t.m = obj.TreatMedicine.mischecked == true ? "M" : "";
                    t.e = obj.TreatMedicine.eischecked == true ? "E" : "";
                    t.n = obj.TreatMedicine.nischecked == true ? "N" : "";
                    var arr = form["particular"].ToString().Split(':');
                    t.medicineid = Convert.ToInt32(arr[0]);
                    t.particular = arr[1];
                    t.qty        = obj.TreatMedicine.qty;
                    t.srno       = obj.srno;
                    if (tm.Where(q => q.particular == t.particular).Count() >= 1)
                    {
                        ViewBag.msg = "Particular already added.";
                    }
                    else
                    {
                        tm.Add(t);
                    }
                    obj.TreatMedicineList        = tm;
                    Session["TreatmentMedicine"] = tm;

                    break;

                case "addcomplent":
                    //Complents
                    TreatmentComplents tcmp = new TreatmentComplents();
                    var complentarr         = form["complents"].ToString().Split(':');
                    tcmp.complentid   = Convert.ToInt32(complentarr[0]);
                    tcmp.complentname = complentarr[1];
                    tcmp.srno         = obj.srno;
                    if (tc.Where(q => q.complentname == tcmp.complentname).Count() >= 1)
                    {
                        ViewBag.complentmsg = "Complent already added.";
                    }
                    else
                    {
                        tc.Add(tcmp);
                    }

                    obj.TreatComplentsList        = tc;
                    Session["TreatmentComplents"] = tc;
                    ViewBag.tab = "tab1";
                    break;

                case "adddiagnosis":
                    //Diagnosis
                    TreatmentDiagnosis tdig = new TreatmentDiagnosis();
                    var diagnosisarr        = form["diagnosis"].ToString().Split(':');
                    tdig.diagnosisid   = Convert.ToInt32(diagnosisarr[0]);
                    tdig.diagnosisname = diagnosisarr[1];
                    tdig.srno          = obj.srno;
                    if (td.Where(q => q.diagnosisname == tdig.diagnosisname).Count() >= 1)
                    {
                        ViewBag.diagnosismsg = "Diagnosis already added.";
                    }
                    else
                    {
                        td.Add(tdig);
                    }

                    obj.TreatDiagnosisList        = td;
                    Session["TreatmentDiagnosis"] = td;
                    break;

                case "addhistory":
                    //Diagnosis
                    TreatmentHistory thistory = new TreatmentHistory();
                    var historyarr            = form["history"].ToString().Split(':');
                    thistory.historyid   = Convert.ToInt32(historyarr[0]);
                    thistory.historyname = historyarr[1];
                    thistory.from_dt     = obj.from_dt;
                    thistory.to_dt       = obj.to_dt;
                    thistory.srno        = obj.srno;
                    if (th.Where(q => q.historyname == thistory.historyname).Count() >= 1)
                    {
                        ViewBag.historymsg = "Disease already added.";
                    }
                    else
                    {
                        th.Add(thistory);
                    }

                    obj.TreatHistoryList        = th;
                    Session["TreatmentHistory"] = th;
                    ViewBag.tab = "tab2";
                    break;

                case "addcheckups":
                    //Diagnosis
                    TreatmentCheckups tcheckup = new TreatmentCheckups();
                    var checkuparr             = form["checkups"].ToString().Split(':');
                    tcheckup.checkupid   = Convert.ToInt32(checkuparr[0]);
                    tcheckup.checkupname = checkuparr[1];
                    tcheckup.srno        = obj.srno;
                    if (tch.Where(q => q.checkupname == tcheckup.checkupname).Count() >= 1)
                    {
                        ViewBag.checkupmsg = "Checkup already added.";
                    }
                    else
                    {
                        tch.Add(tcheckup);
                    }

                    obj.TreatCheckupList         = tch;
                    Session["TreatmentCheckups"] = tch;
                    break;

                case "addfundus":
                    //Diagnosis
                    TreatmentFundus tfundus   = new TreatmentFundus();
                    var             fundusarr = form["fundus"].ToString().Split(':');
                    tfundus.fundusid   = Convert.ToInt32(fundusarr[0]);
                    tfundus.fundusname = fundusarr[1];
                    tfundus.srno       = obj.srno;
                    if (tch.Where(q => q.checkupname == tfundus.fundusname).Count() >= 1)
                    {
                        ViewBag.fundusmsg = "Fundus already added.";
                    }
                    else
                    {
                        tf.Add(tfundus);
                    }

                    obj.TreatFundusList        = tf;
                    Session["TreatmentFundus"] = tf;
                    break;

                case "addadvice":
                    //Diagnosis
                    TreatmentAdvice tad   = new TreatmentAdvice();
                    var             adarr = form["advice"].ToString().Split(':');
                    tad.adviceid   = Convert.ToInt32(adarr[0]);
                    tad.advicename = adarr[1];
                    tad.srno       = obj.srno;
                    if (ta.Where(q => q.advicename == tad.advicename).Count() >= 1)
                    {
                        ViewBag.fundusmsg = "Advice already added.";
                    }
                    else
                    {
                        ta.Add(tad);
                    }
                    obj.TreatAdviceList        = ta;
                    Session["TreatmentAdvice"] = ta;
                    break;

                case "Delete":
                    //Medicines
                    int index = Convert.ToInt32(form["medicinesrno"]);
                    tm.RemoveAt(index);
                    Session["TreatmentMedicine"] = obj.TreatMedicineList = tm;
                    break;

                case "DeleteComplent":
                    //Complents
                    int complentsrno = Convert.ToInt32(form["complentsrno"]);
                    tc.RemoveAt(complentsrno);
                    Session["TreatmentComplents"] = obj.TreatComplentsList = tc;
                    break;

                case "DeleteDiagnosis":
                    //Diagnosis
                    int diagnosissrno = Convert.ToInt32(form["diagsrno"]);
                    td.RemoveAt(diagnosissrno);
                    Session["TreatmentDiagnosis"] = obj.TreatDiagnosisList = td;
                    break;

                case "DeleteHistory":
                    //History
                    int historysrno = Convert.ToInt32(form["historysrno"]);
                    th.RemoveAt(historysrno);
                    Session["TreatmentHistory"] = obj.TreatHistoryList = th;
                    break;

                case "DeleteCheckup":
                    //History
                    int checkupsrno = Convert.ToInt32(form["checkupsrno"]);
                    tch.RemoveAt(checkupsrno);
                    Session["TreatmentCheckup"] = obj.TreatCheckupList = tch;
                    break;

                case "DeleteFundus":
                    //History
                    int fundussrno = Convert.ToInt32(form["fundussrno"]);
                    tf.RemoveAt(fundussrno);
                    Session["TreatmentFundus"] = obj.TreatFundusList = tf;
                    break;

                case "DeleteAdvice":
                    //History
                    int advicesrno = Convert.ToInt32(form["advicesrno"]);
                    ta.RemoveAt(advicesrno);
                    Session["TreatmentAdvice"] = obj.TreatAdviceList = ta;
                    break;

                case "Reset":
                    resetflag = 1;
                    break;

                case "Save":

                    Session["TreatmentMedicine"]  = obj.TreatMedicineList = tm;
                    Session["TreatmentComplents"] = obj.TreatComplentsList = tc;
                    Session["TreatmentDiagnosis"] = obj.TreatDiagnosisList = td;
                    Session["TreatmentHistory"]   = obj.TreatHistoryList = th;
                    Session["TreatmentCheckups"]  = obj.TreatCheckupList = tch;
                    Session["TreatmentFundus"]    = obj.TreatFundusList = tf;
                    Session["treatmentAdvice"]    = obj.TreatAdviceList = ta;
                    string treatmentid = obj.PerformAction();
                    Session["treatmentid"] = treatmentid;
                    string str = PrintGenerator.GenerateTreatmentPDF();
                    TempData["Print"] = str;
                    return(RedirectToAction("Print", "Shared"));

                case "Update":
                    Session["TreatmentMedicine"]  = obj.TreatMedicineList = tm;
                    Session["TreatmentComplents"] = obj.TreatComplentsList = tc;
                    Session["TreatmentDiagnosis"] = obj.TreatDiagnosisList = td;
                    Session["TreatmentHistory"]   = obj.TreatHistoryList = th;
                    Session["TreatmentCheckups"]  = obj.TreatCheckupList = tch;
                    Session["TreatmentFundus"]    = obj.TreatFundusList = tf;
                    Session["treatmentAdvice"]    = obj.TreatAdviceList = ta;
                    string treatid = obj.PerformAction();
                    Session["treatmentid"] = treatid;
                    string str1 = PrintGenerator.GenerateTreatmentPDF();
                    TempData["Print"] = str1;
                    return(RedirectToAction("Print", "Shared"));
                }

                if (resetflag == 1)
                {
                    return(Redirect("/Patient/Treatment"));
                }


                if (obj.TreatInvestigationList != null)
                {
                    Session["TreatInvestigationList"] = obj.TreatInvestigationList;
                }
                else
                {
                    obj.TreatInvestigationList = (List <TreatmentInvestigation>)Session["TreatInvestigationList"];
                }
            }
            catch (Exception e)
            {
                string[] arr = new string[2] {
                    "danger", "Something Went Wrong! Try later." + e.Message
                };

                ViewBag.msgarr = arr;
            }

            return(View(obj));
        }
Ejemplo n.º 17
0
        public ActionResult status(string approv, int id, string details)
        {
            //var user = db.Users.Where(u => "kk" + u.JobNumber == User.Identity.Name).FirstOrDefault();
            var              user             = db.Users.Where(u => u.JobNumber == User.Identity.Name).FirstOrDefault();
            RequestItem      request          = db.RequestItems.Where(r => r.RequestItemsId == id).FirstOrDefault();
            TreatmentHistory treatmentHistory = new TreatmentHistory();

            if (user.Position.NameEn == "Director" && user.UserId == request.User.Department.ManagerId || user.Position.NameEn == "Director" && user.UserRoles.FirstOrDefault().Role.NameEn == "IT Manager")
            {
                switch (Convert.ToInt32(approv))
                {
                case 1:
                    request.StutusId = db.RequestStatus.Where(s => s.StatusCode == "ITS").First().RequestStatusId;
                    break;

                case 2:
                    request.StutusId = db.RequestStatus.Where(s => s.StatusCode == "RBD").First().RequestStatusId;
                    request.DirectorRecommondation = details;
                    break;

                case 3:
                    request.StutusId = db.RequestStatus.Where(s => s.StatusCode == "RWH").First().RequestStatusId;
                    Item item = db.Items.Where(i => i.ItemId == request.ItemId).FirstOrDefault();

                    int?UnitsOnOrder = request.Quantity;
                    int?UnitsInStock = request.Quantity;
                    if (item.UnitsInStock != null && item.UnitsOnOrder != null)
                    {
                        UnitsOnOrder = item.UnitsOnOrder + UnitsOnOrder;
                        UnitsInStock = item.UnitsInStock - UnitsInStock;
                    }


                    item.UnitsOnOrder    = UnitsOnOrder;
                    item.UnitsInStock    = UnitsInStock;
                    db.Entry(item).State = EntityState.Modified;
                    break;

                case 4:
                    request.StutusId = db.RequestStatus.Where(s => s.StatusCode == "RIT").First().RequestStatusId;
                    break;

                default:
                    break;
                }
            }
            if (User.IsInRole("Supervisor"))
            {
                switch (Convert.ToInt32(approv))
                {
                case 4:
                    request.StutusId = db.RequestStatus.Where(s => s.StatusCode == "RIT").First().RequestStatusId;
                    break;

                case 5:
                    request.StutusId = db.RequestStatus.Where(s => s.StatusCode == "NITA").First().RequestStatusId;
                    break;

                case 6:
                    request.StutusId = db.RequestStatus.Where(s => s.StatusCode == "RWH").First().RequestStatusId;
                    Item item = db.Items.Where(i => i.ItemId == request.ItemId).FirstOrDefault();

                    int?UnitsOnOrder = request.Quantity;
                    int?UnitsInStock = request.Quantity;
                    if (item.UnitsInStock != null && item.UnitsOnOrder != null)
                    {
                        UnitsOnOrder = item.UnitsOnOrder + UnitsOnOrder;
                        UnitsInStock = item.UnitsInStock - UnitsInStock;
                    }
                    item.UnitsOnOrder    = UnitsOnOrder;
                    item.UnitsInStock    = UnitsInStock;
                    db.Entry(item).State = EntityState.Modified;

                    break;

                case 7:
                    request.StutusId = db.RequestStatus.Where(s => s.StatusCode == "NTR").First().RequestStatusId;
                    break;

                case 8:
                    request.StutusId = db.RequestStatus.Where(s => s.StatusCode == "PEND").First().RequestStatusId;
                    break;

                case 10:
                    request.StutusId = db.RequestStatus.Where(s => s.StatusCode == "ITS").First().RequestStatusId;
                    break;

                default:
                    break;
                }
            }

            if (User.IsInRole("Warehouse Admin"))
            {
                switch (Convert.ToInt32(approv))
                {
                case 9:
                    request.StutusId = db.RequestStatus.Where(s => s.StatusCode == "DONE").First().RequestStatusId;

                    Item item = db.Items.Where(i => i.ItemId == request.ItemId).FirstOrDefault();

                    int?UnitsOnOrder = request.Quantity;

                    if (UnitsOnOrder != null)
                    {
                        UnitsOnOrder = item.UnitsOnOrder - UnitsOnOrder;
                    }

                    item.UnitsOnOrder    = UnitsOnOrder;
                    db.Entry(item).State = EntityState.Modified;

                    break;

                default:
                    break;
                }
            }

            if (User.IsInRole("Technician"))
            {
                switch (Convert.ToInt32(approv))
                {
                case 10:
                    request.StutusId = db.RequestStatus.Where(s => s.StatusCode == "ITS").First().RequestStatusId;
                    break;

                default:
                    break;
                }
            }
            //// History Action
            treatmentHistory.User           = user;
            treatmentHistory.RequestItem    = request;
            treatmentHistory.RequestStatu   = db.RequestStatus.Where(s => s.RequestStatusId == request.StutusId).First();
            treatmentHistory.LastUpdateBy   = user.FirstNameEn + " " + user.LastNameEn;
            treatmentHistory.LastUpdateDate = DateTime.Today;
            db.TreatmentHistories.Add(treatmentHistory);

            request.LastUpdateBy    = user.FirstNameEn + " " + user.LastNameEn;
            request.LastUpdateDate  = DateTime.Today;
            db.Entry(request).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Details/" + id));
        }
 public JObject Edit(TreatmentHistory treatmentHistory)
 {
     _db.Entry(treatmentHistory).State = EntityState.Modified;
     _db.SaveChanges();
     dynamic result = new JObject();
     result.result = "ok";
     return result;
 }