public Sampling DuplicateSamplingRecord(Sampling entity) { Sampling sampling = new Sampling(); sampling.BarCode = entity.BarCode; sampling.Iteration = entity.Iteration; sampling.Location = entity.Location; sampling.Comment = entity.Comment; sampling.SamplingType_Id = entity.SamplingType_Id; sampling.SamplingStatus_Id = entity.SamplingStatus_Id; sampling.Appointment_Id = entity.Appointment_Id; return(sampling); }
public ActionResult CreateOrEditSampling(Sampling sampling) { // Bug fix // Permet de mettre a true ModelState.IsValid // Le binding ne se fait pas correctement pour SamplingType.Id. ModelState.Remove("SamplingType.Id"); if (ModelState.IsValid) { AddNewEntityIfNecessary(sampling); if (sampling.Id == 0) { db.Samplings.Add(sampling); } else { var samplingFromDb = db.Samplings.First(s => s.Id == sampling.Id); samplingFromDb.SamplingStatus_Id = sampling.SamplingStatus_Id; samplingFromDb.SamplingType_Id = sampling.SamplingType_Id; samplingFromDb.BarCode = sampling.BarCode; samplingFromDb.Iteration = sampling.Iteration; samplingFromDb.Location = sampling.Location; samplingFromDb.Comment = sampling.Comment; samplingFromDb.Results = sampling.Results; } db.SaveChanges(User.Identity.Name); ViewBag.ApppointmentId = sampling.Appointment_Id; var appointment = db.Appointments.Include(a => a.Samplings.Select(s => s.SamplingStatu)) .Include(a => a.Samplings.Select(s => s.SamplingType)) .First(a => a.Id == sampling.Appointment_Id); ViewBag.SamplingType_Id = new SelectList(db.SamplingTypes, "Id", Session["Language"].ToString().ToLower() == "en" ? "Name" : "NameFr"); ViewBag.SamplingStatus_Id = new SelectList(db.SamplingStatus, "Id", Session["Language"].ToString().ToLower() == "en" ? "Name" : "NameFr"); return(Json(new { success = true, html = this.RenderPartialViewToString("_ListSamplings", appointment) })); } ViewBag.SamplingStatus_Id = new SelectList(db.SamplingStatus, "Id", "Name", sampling.SamplingStatus_Id); ViewBag.SamplingType_Id = new SelectList(db.SamplingTypes, "Id", "Name", sampling.SamplingType_Id); return(Json(new { success = false, message = "form is invalid" })); }
private void AddNewEntityIfNecessary(Sampling sampling) { bool newSamplingTypeMustBeAdded = sampling.SamplingType_Id < 1 && sampling.SamplingType.Name != String.Empty; if (newSamplingTypeMustBeAdded) { SamplingType newSamplingType = new SamplingType() { IsActive = true, Name = sampling.SamplingType.Name, NameFr = sampling.SamplingType.Name }; db.SamplingTypes.Add(newSamplingType); db.SaveChanges(); sampling.SamplingType = newSamplingType; sampling.SamplingType_Id = newSamplingType.Id; } }
public JsonResult CreateIteration(int id) { string result = "Couldn't able to create."; if (id > 0) { var sampling = db.Samplings.Where(i => i.Id == id).FirstOrDefault(); if (sampling != null) { Sampling samplingIteration = DuplicateSamplingRecord(sampling); samplingIteration.Iteration = sampling.Iteration + 1; db.Samplings.Add(samplingIteration); db.SaveChanges(User.Identity.Name); result = "Sampling iteration added successfully"; } else { result = "Sampling doesn't exists."; } } return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult GenerateSampling(int id, int barCode) { string result = "Couldn't able to create."; if (id > 0) { var samplingEntity = db.Samplings.Where(i => i.Id == id).FirstOrDefault(); if (samplingEntity != null) { // 1-Plasma / Starting Bar Code Sampling sampling = DuplicateSamplingRecord(samplingEntity); sampling.BarCode = "1-Plasma " + barCode; sampling.SamplingType_Id = 4; db.Samplings.Add(sampling); // 2-Plasma / Starting Bar Code + 1 sampling = DuplicateSamplingRecord(samplingEntity); sampling.BarCode = "2-Plasma " + (barCode + 1); sampling.SamplingType_Id = 4; db.Samplings.Add(sampling); // 3-Red Cell / Starting Bar Code + 2 sampling = DuplicateSamplingRecord(samplingEntity); sampling.BarCode = "3-Red Cell " + (barCode + 2); sampling.SamplingType_Id = 1; db.Samplings.Add(sampling); // 4-Red Cell / Starting Bar Code + 3 sampling = DuplicateSamplingRecord(samplingEntity); sampling.BarCode = "4-Red Cell " + (barCode + 3); sampling.SamplingType_Id = 1; db.Samplings.Add(sampling); // 5-Red Cell / Starting Bar Code + 4 sampling = DuplicateSamplingRecord(samplingEntity); sampling.BarCode = "5-Red Cell " + (barCode + 4); sampling.SamplingType_Id = 1; db.Samplings.Add(sampling); // 6-White Cell / Starting Bar Code + 5 sampling = DuplicateSamplingRecord(samplingEntity); sampling.BarCode = "6-White Cell " + (barCode + 5); sampling.SamplingType_Id = 1; db.Samplings.Add(sampling); // 7-White Cell / Starting Bar Code + 6 sampling = DuplicateSamplingRecord(samplingEntity); sampling.BarCode = "7-White Cell " + (barCode + 6); sampling.SamplingType_Id = 1; db.Samplings.Add(sampling); samplingEntity.SamplingStatus_Id = 2; // The System update the Original Sampling Status to "Consume" db.SaveChanges(User.Identity.Name); result = "Sampling iteration added successfully"; } else { result = "Sampling doesn't exists."; } } return(Json(result, JsonRequestBehavior.AllowGet)); }