Example #1
0
        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"));
            }
        }
Example #2
0
        public JsonResult Edit(string jsonAssetAttribute, string asset)
        {
            string error         = "false";
            string errorQuantity = "false";

            try
            {
                TempData.Remove("checkScreenArea");
                String assetString = HttpUtility.HtmlDecode(asset);
                List <AssetAttributeValue> assetAttributeValue = JsonConvert.DeserializeObject <List <AssetAttributeValue> >(jsonAssetAttribute);
                Asset assetViewModel = JsonConvert.DeserializeObject <Asset>(assetString);
                //assetViewModel.ApplicationUserID = Convert.ToInt32(User.Identity.GetUserId());

                var validateName = _assetService.GetAll(new string[] { "Area", "Area.Location" }).FirstOrDefault
                                       (x => x.Name == assetViewModel.Name && x.Area.ID == assetViewModel.AreaID && x.ID != assetViewModel.ID);
                if (validateName != null)
                {
                    error = "Name Asset already exists in Area";
                }
                else
                {
                    _assetService.Update(assetViewModel, assetAttributeValue);
                    SetAlert("Update Asset success", "success");
                    AssetLog assetLog = new AssetLog
                    {
                        AssetID           = assetViewModel.ID,
                        Active            = true,
                        CreatedAt         = DateTime.Now,
                        Message           = "Asset Updated",
                        ApplicationUserID = applicationUserManager.FindByName(User.Identity.GetUserName()).Id
                    };

                    _assetLogService.Add(assetLog);
                    _assetLogService.SaveChanges();
                }
                // update asset log
            }
            catch (Exception e)
            {
                SetAlert("Update Asset error", "error");
            }
            return(Json(error));
        }