public ActionResult Edit(ReportViewModel viewModel, string alternativeMaterials, string reportArea) { // TODO: Add update logic here var report = _reportService.GetById(viewModel.ID, new string[] { "Asset", "Asset.Area" }); report.status = viewModel.status; if (viewModel.Comment != null) { report.Comment = report.Comment + "\n -> " + User.Identity.GetUserName() + ": " + viewModel.Comment; } report.UpdatedAt = DateTime.Now; _reportService.Update(report); _reportService.SaveChanges(); if (viewModel.status == 3) { MaintenanceDiary maintenanceDiary = new MaintenanceDiary { AssetID = report.Asset.ID, MaintenanceDate = DateTime.Now, Active = true, Description = alternativeMaterials }; _maintenanceDiaryService.Add(maintenanceDiary); _maintenanceDiaryService.SaveChanges(); } AssetLog assetLog = new AssetLog { AssetID = report.Asset.ID, Active = true, CreatedAt = DateTime.Now, Message = "Report ID: " + report.ID + " at asset code: " + report.Asset.AssetCode + " Status: " + Enum.GetName(typeof(StatusReport), report.status), ApplicationUserID = applicationUserManager.FindByName(User.Identity.GetUserName()).Id }; _assetLogService.Add(assetLog); _assetLogService.SaveChanges(); if (reportArea.Equals("true")) { var listAssetInArea = _assetService.GetAllByAreaID(report.Asset.Area.ID); int idAssetArea = 0; foreach (var asset in listAssetInArea) { if (asset.AssetCode.StartsWith("A")) { idAssetArea = asset.ID; break; } } return(Redirect("~/Report/ListReportArea/" + idAssetArea)); } else { SetAlert("Update Report success", "success"); return(RedirectToAction("Index")); } }
public ActionResult Create(MaintenanceDiaryViewModel viewModel) { var maintenanceDiary = new MaintenanceDiary() { MaintenanceDate = viewModel.MaintenanceDate, Description = viewModel.Description, AssetID = viewModel.Asset.ID, Active = true }; _maintenanceDiaryService.Add(maintenanceDiary); _maintenanceDiaryService.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult CreateAll(FormCollection form) { try { ViewBag.allAssetSelect = form["assetCheckedList"]; ViewBag.currentDate = DateTime.Now.ToString("yyyy-MM-dd"); ViewBag.returnUrl = form["returnUrl"]; if (!string.IsNullOrEmpty(form["dateMaintenance"])) { var dateMaintenance = form["dateMaintenance"]; var allAssetSelect = form["assetCheckedList"] != null ? form["assetCheckedList"].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList() : new List <int>(); foreach (int assetId in allAssetSelect) { var maintenanceDiary = new MaintenanceDiary() { MaintenanceDate = DateTime.Parse(dateMaintenance), Description = form["description"], AssetID = assetId, Active = true }; _maintenanceDiaryService.Add(maintenanceDiary); _maintenanceDiaryService.SaveChanges(); } SetAlert("Add Maintenance Diary success", "success"); return(RedirectToAction("Index")); } }catch (Exception e) { SetAlert("Add Maintenance Diary error", "error"); } return(View()); }
public void Update(MaintenanceDiary maintenanceDiary) { _maintenanceDiaryRepository.Update(maintenanceDiary); }
public void Add(MaintenanceDiary maintenanceDiary) { _maintenanceDiaryRepository.Add(maintenanceDiary); }