コード例 #1
0
ファイル: ReportController.cs プロジェクト: quyennt21/cim
        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"));
            }
        }
コード例 #2
0
        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"));
        }
コード例 #3
0
        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());
        }
コード例 #4
0
 public void Update(MaintenanceDiary maintenanceDiary)
 {
     _maintenanceDiaryRepository.Update(maintenanceDiary);
 }
コード例 #5
0
 public void Add(MaintenanceDiary maintenanceDiary)
 {
     _maintenanceDiaryRepository.Add(maintenanceDiary);
 }