public ActionResult Create(RawMaterialReceived rawMaterialReceived, string action) { if (action == "create") { if (ModelState.IsValid) { var dto = Mapper.Map <RawMaterialReceived, RawMaterialReceivedDto>(rawMaterialReceived); //TODO: move to service dto.ModifiedBy = CurrentUser; using (var service = new RawMaterialReceivedService()) { service.Add(dto); } SetResponseMesssage(ActionTypeMessage.SuccessfulSave); } else { ViewBag.PlantId = CurrentPlantId; rawMaterialReceived.ProductionLines = GetProductionLines(); ModelState.AddModelError(string.Empty, "Please enter required fields."); SetResponseMesssage(ActionTypeMessage.FailedSave); return(View(rawMaterialReceived)); } } if (rawMaterialReceived.UrlReferrer != null && rawMaterialReceived.UrlReferrer.Contains("RawMaterialQC")) { return(RedirectToAction("Index", "RawMaterialQC")); } return(RedirectToAction("Index")); }
private string GetIMRollNumber(IProductEntryDto tpoCProductRollDto, ProductionLinesDto prodLineDto) { bool old = false; string newLotNumber = GetNewLotNumber(tpoCProductRollDto); if (tpoCProductRollDto.RawMaterialReceivedID != 0) { try { RawMaterialReceived rm = _repository.Repository <RawMaterialReceived>().GetById(tpoCProductRollDto.RawMaterialReceivedID); if (rm.LotNumber.Substring(0, 7) != newLotNumber) { old = true; } } catch { old = true; } } WorkOrder workOrder = _repository.Repository <WorkOrder>().GetById(tpoCProductRollDto.WorkOrderID); string newProdCode = string.Empty; if (old) { newProdCode = FillOldIMLot(newLotNumber, workOrder); } else { newProdCode = FillCurrentIMLot(newLotNumber, workOrder); } return(newProdCode); }
public ActionResult Delete(int id, string action) { try { using (var service = new RawMaterialReceivedService()) { service.Delete(id); } SetResponseMesssage(ActionTypeMessage.SuccessfulDelete); } catch (Exception ex) { //TODO: Move to service if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("FK_RawMaterialQCRedHold_RawMaterialReceived")) { using (var service = new RawMaterialReceivedService()) { RawMaterialReceived model = Mapper.Map <RawMaterialReceivedDto, RawMaterialReceived>(service.Get(id)); model.ProductionLines = GetProductionLines(); SetResponseMesssage(ActionTypeMessage.Error, General.ResponseMessageMaterialAssociated); return(View(model)); } } } return(RedirectToAction("Index")); }
public JsonResult AjaxTypeDelete(string row) { ResponseMessage responseMessage; RawMaterialReceived rawMaterialReceived = JsonConvert.DeserializeObject <RawMaterialReceived>(row); try { if (rawMaterialReceived != null) { RawMaterialReceivedDto dto = new RawMaterialReceivedDto(); using (RawMaterialReceivedService service = new RawMaterialReceivedService()) { Mapper.Map(rawMaterialReceived, dto); if (rawMaterialReceived.Id > 0) { service.DeleteComplete(dto.Id); } } } responseMessage = SetResponseMesssage(ActionTypeMessage.SuccessfulSave); } catch (Exception exc) { responseMessage = SetResponseMesssage(ActionTypeMessage.FailedSave, exc.Message); } return(Json(responseMessage, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit(int?id) { if (id != null) { using (var service = new RawMaterialReceivedService()) { RawMaterialReceived model = Mapper.Map <RawMaterialReceivedDto, RawMaterialReceived>(service.Get(id.Value)); model.ProductionLines = GetProductionLines(); return(View(model)); } } SetResponseMesssage(ActionTypeMessage.Error, General.ResponseMessageFailNoId); return(RedirectToAction("Index")); }
public ActionResult Create() { ViewBag.RawMaterial = GetProductionLines(); ViewBag.PlantId = CurrentPlantId; var model = new RawMaterialReceived { ProductionLines = GetProductionLines(), DateEntered = DateTime.Now, ModifiedBy = CurrentUser, EnteredBy = CurrentUser, UrlReferrer = System.Web.HttpContext.Current.Request.UrlReferrer.LocalPath }; return(View(model)); }
public int Add(RawMaterialReceivedDto rawMaterialReceivedDto) { var newRawMaterialReceived = new RawMaterialReceived(); try { //rawMaterialReceivedDto.RawMaterialId = 1; rawMaterialReceivedDto.LastModified = DateTime.Now; rawMaterialReceivedDto.ModifiedBy = CurrentUserName; rawMaterialReceivedDto.EnteredBy = CurrentUserName; rawMaterialReceivedDto.DateEntered = DateTime.Now; Mapper.Map(rawMaterialReceivedDto, newRawMaterialReceived); _repository.Repository <RawMaterialReceived>().Insert(newRawMaterialReceived); _repository.Save(); } catch (DbEntityValidationException valEx) { var sb = new StringBuilder(); foreach (var failure in valEx.EntityValidationErrors) { sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new DbEntityValidationException( "Entity Validation Failed - errors follow:\n" + sb.ToString(), valEx ); // Add the original exception as the innerException } catch (Exception ex) { LogException(ex); throw; } return(newRawMaterialReceived.ID); }
public ActionResult AjaxTypeUpdate(string row, string rawMaterialId) { ResponseMessage responseMessage; RawMaterialReceived rawMaterialReceived = JsonConvert.DeserializeObject <RawMaterialReceived>(row); try { if (rawMaterialReceived != null) { rawMaterialReceived.LastModified = DateTime.Now; RawMaterialReceivedDto dto = new RawMaterialReceivedDto(); using (RawMaterialReceivedService service = new RawMaterialReceivedService()) { Mapper.Map(rawMaterialReceived, dto); if (rawMaterialReceived.Id > 0) { service.Update(dto); } else { dto.RawMaterialId = Convert.ToInt32(rawMaterialId); dto.PlantId = CurrentPlantId; service.Add(dto); } } } responseMessage = SetResponseMesssage(ActionTypeMessage.SuccessfulSave); } catch (Exception exc) { responseMessage = SetResponseMesssage(ActionTypeMessage.FailedSave, exc.Message); } return(Json(responseMessage, JsonRequestBehavior.AllowGet)); }