// // GET: /Production/Edit public ActionResult Edit(string companyCode, string plantWerk, string faCode, DateTime wasteProductionDate) { if (CurrentUser.UserRole == Enums.UserRole.Viewer || CurrentUser.UserRole == Enums.UserRole.Controller) { return(RedirectToAction("Edit", "Production", new { companyCode = companyCode, plantWerk = plantWerk, faCode = faCode, wasteProductionDate = wasteProductionDate })); } var model = new WasteDetail(); var dbWaste = _wasteBll.GetById(companyCode, plantWerk, faCode, wasteProductionDate); model = Mapper.Map <WasteDetail>(dbWaste); model = IniEdit(model); model.CompanyCodeX = model.CompanyCode; model.PlantWerksX = model.PlantWerks; model.WasteProductionDateX = model.WasteProductionDate; model.FaCodeX = model.FaCode; return(View(model)); }
public IHttpActionResult PutWasteDetail(int id, WasteDetail wasteDetail) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != wasteDetail.WasteId) { return(BadRequest()); } db.Entry(wasteDetail).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!WasteDetailExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private WasteDetail IniEdit(WasteDetail model) { model.MainMenu = _mainMenu; model.CurrentMenu = PageInfo; var company = GlobalFunctions.GetCompanyList(_companyBll); if (CurrentUser.UserRole != Enums.UserRole.Administrator) { var userPlantCompany = _userPlantMapBll.GetCompanyByUserId(CurrentUser.USER_ID); var poaMapCompany = _poaMapBll.GetCompanyByPoaId(CurrentUser.USER_ID); var distinctCompany = company.Where(x => userPlantCompany.Contains(x.Value)); if (CurrentUser.UserRole == Enums.UserRole.POA) { distinctCompany = company.Where(x => poaMapCompany.Contains(x.Value)); } var getCompany = new SelectList(distinctCompany, "Value", "Text"); company = getCompany; } model.CompanyCodeList = company; model.PlantWerkList = GlobalFunctions.GetPlantByCompanyId(""); model.FacodeList = GlobalFunctions.GetFaCodeByPlant(""); return(model); }
private WasteDetail InitDetail(WasteDetail model) { model.MainMenu = _mainMenu; model.CurrentMenu = PageInfo; model.CompanyCodeList = GlobalFunctions.GetCompanyList(_companyBll); model.PlantWerkList = GlobalFunctions.GetPlantAll(); model.FacodeList = GlobalFunctions.GetBrandList(); return(model); }
public JsonResult GetBrandCeByPlant(string plantWerk) { var listBrandCe = GlobalFunctions.GetFaCodeByPlant(plantWerk); var model = new WasteDetail() { FacodeList = listBrandCe }; return(Json(model)); }
public IHttpActionResult GetWasteDetail(int id) { WasteDetail wasteDetail = db.WasteDetails.Find(id); if (wasteDetail == null) { return(NotFound()); } return(Ok(wasteDetail)); }
public ActionResult Create(WasteDetail model) { if (ModelState.IsValid) { var param = new MonthClosingGetByParam(); param.ClosingDate = Convert.ToDateTime(model.WasteProductionDate); param.PlantId = model.PlantWerks; param.DisplayDate = null; var monthClosingdata = _monthClosingBll.GetDataByParam(param); if (monthClosingdata != null) { AddMessageInfo("Please check closing date.", Enums.MessageInfoType.Warning); model = InitCreate(model); model.CompanyCode = model.CompanyCode; model.PlantWerks = model.PlantWerks; model.FaCode = model.FaCode; model.WasteProductionDate = model.WasteProductionDate; return(View(model)); } var existingData = _wasteBll.GetExistDto(model.CompanyCode, model.PlantWerks, model.FaCode, Convert.ToDateTime(model.WasteProductionDate)); if (existingData != null) { AddMessageInfo("Data Already Exist", Enums.MessageInfoType.Warning); return(RedirectToAction("Edit", "Waste", new { companyCode = model.CompanyCode, plantWerk = model.PlantWerks, faCode = model.FaCode, wasteProductionDate = model.WasteProductionDate })); } var data = Mapper.Map <WasteDto>(model); try { _wasteBll.Save(data, CurrentUser.USER_ID); AddMessageInfo(Constans.SubmitMessage.Saved, Enums.MessageInfoType.Success); return(RedirectToAction("Index")); } catch (Exception exception) { AddMessageInfo(exception.Message, Enums.MessageInfoType.Error); } } model = InitCreate(model); return(View(model)); }
public IHttpActionResult PostWasteDetail(WasteDetail wasteDetail) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.WasteDetails.Add(wasteDetail); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = wasteDetail.WasteId }, wasteDetail)); }
public ActionResult Detail(string companyCode, string plantWerk, string faCode, DateTime wasteProductionDate) { var model = new WasteDetail(); var dbWaste = _wasteBll.GetById(companyCode, plantWerk, faCode, wasteProductionDate); model = Mapper.Map <WasteDetail>(dbWaste); model.ChangesHistoryList = Mapper.Map <List <ChangesHistoryItemModel> >(_changeHistoryBll.GetByFormTypeAndFormId(Enums.MenuList.CK4C, "Waste_" + companyCode + "_" + plantWerk + "_" + faCode + "_" + wasteProductionDate.ToString("ddMMMyyyy"))); model = InitDetail(model); return(View(model)); }
public IHttpActionResult DeleteWasteDetail(int id) { WasteDetail wasteDetail = db.WasteDetails.Find(id); if (wasteDetail == null) { return(NotFound()); } db.WasteDetails.Remove(wasteDetail); db.SaveChanges(); return(Ok(wasteDetail)); }
private void MoveOldChangeLogHistory(WasteDetail item) { DateTime DateX = Convert.ToDateTime(item.WasteProductionDateX); DateTime Date = Convert.ToDateTime(item.WasteProductionDate); var listHistory = _changeHistoryBll.GetByFormTypeAndFormId(Enums.MenuList.CK4C, "Waste_" + item.CompanyCodeX + "_" + item.PlantWerksX + "_" + item.FaCodeX + "_" + DateX.ToString("ddMMMyyyy")); var oldFormId = "Waste_" + item.CompanyCode + "_" + item.PlantWerks + "_" + item.FaCode + "_" + Date.ToString("ddMMMyyyy"); foreach (var data in listHistory) { _changeHistoryBll.MoveHistoryToNewData(data, oldFormId); } }
public ActionResult Create() { if (CurrentUser.UserRole == Enums.UserRole.Viewer || CurrentUser.UserRole == Enums.UserRole.Administrator || CurrentUser.UserRole == Enums.UserRole.Controller) { AddMessageInfo("Operation not allow", Enums.MessageInfoType.Error); return(RedirectToAction("Index")); } var model = new WasteDetail(); model = InitCreate(model); model.WasteProductionDate = DateTime.Today.ToString("dd MMM yyyy"); return(View(model)); }
public JsonResult CompanyListPartialProduction(string companyId) { var listPlant = GlobalFunctions.GetPlantByCompanyId(companyId); if (CurrentUser.UserRole != Enums.UserRole.Administrator) { var userPlantMap = _userPlantMapBll.GetPlantByUserId(CurrentUser.USER_ID); var poaMap = _poaMapBll.GetCompanyByPoaId(CurrentUser.USER_ID); var distinctPlant = listPlant.Where(x => userPlantMap.Contains(x.Value) || poaMap.Contains(x.Value)); var listPlantNew = new SelectList(distinctPlant, "Value", "Text"); listPlant = listPlantNew; } var model = new WasteDetail() { PlantWerkList = listPlant }; return(Json(model)); }
public ActionResult Edit(WasteDetail model) { var dbWaste = _wasteBll.GetById(model.CompanyCodeX, model.PlantWerksX, model.FaCodeX, Convert.ToDateTime(model.WasteProductionDateX)); if (dbWaste == null) { ModelState.AddModelError("Waste", "Data is not Found"); model = IniEdit(model); return(View("Edit", model)); } var param = new MonthClosingGetByParam(); param.ClosingDate = Convert.ToDateTime(model.WasteProductionDate); param.PlantId = model.PlantWerks; param.DisplayDate = null; var monthClosingdata = _monthClosingBll.GetDataByParam(param); if (monthClosingdata != null) { AddMessageInfo("Please check closing date.", Enums.MessageInfoType.Warning); model = IniEdit(model); model.CompanyCode = model.CompanyCode; model.PlantWerks = model.PlantWerks; model.FaCode = model.FaCode; model.WasteProductionDate = model.WasteProductionDate; return(View("Edit", model)); } if (model.CompanyCode != model.CompanyCodeX || model.PlantWerks != model.PlantWerksX || model.FaCode != model.FaCodeX || Convert.ToDateTime(model.WasteProductionDate) != Convert.ToDateTime(model.WasteProductionDateX)) { var existingData = _wasteBll.GetExistDto(model.CompanyCode, model.PlantWerks, model.FaCode, Convert.ToDateTime(model.WasteProductionDate)); if (existingData != null) { AddMessageInfo("Data Already Exist", Enums.MessageInfoType.Warning); return(RedirectToAction("Edit", "Waste", new { companyCode = model.CompanyCode, plantWerk = model.PlantWerks, faCode = model.FaCode, wasteProductionDate = model.WasteProductionDate })); } } var dbWasteNew = Mapper.Map <WasteDto>(model); try { if (!ModelState.IsValid) { var error = ModelState.Values.Where(c => c.Errors.Count > 0).ToList(); if (error.Count > 0) { // } } var isNewData = _wasteBll.Save(dbWasteNew, CurrentUser.USER_ID); var message = Constans.SubmitMessage.Updated; if (model.CompanyCode != model.CompanyCodeX || model.PlantWerks != model.PlantWerksX || model.FaCode != model.FaCodeX || Convert.ToDateTime(model.WasteProductionDate) != Convert.ToDateTime(model.WasteProductionDateX)) { MoveOldChangeLogHistory(model); _wasteBll.DeleteOldData(model.CompanyCodeX, model.PlantWerksX, model.FaCodeX, Convert.ToDateTime(model.WasteProductionDateX)); } AddMessageInfo(message, Enums.MessageInfoType.Success); return(RedirectToAction("Index")); } catch (Exception) { AddMessageInfo("Edit Failed.", Enums.MessageInfoType.Error); } model = IniEdit(model); return(View("Edit", model)); }