public ActionResult SendRequestForScrapping(SendRequestForScrappingViewModel model) { var asset = this.assetService.GetById(model.InventoryNumber); //Verify if asset is from user organisation if (!this.IsMegaAdmin()) { if (asset.Site.OrganisationId != this.userService.GetUserOrganisationId(this.User.Identity.GetUserId())) { return(Redirect("/Home/NotAuthorized")); } } //Check is there a request for this asset if (this.requestForScrappingService.Exist(model.InventoryNumber)) { return(Redirect("/AssetsActions/ScrappingAsset/ThereIsRequest")); } var request = new RequestForScrapping { AssetId = model.InventoryNumber, IsApproved = false, FromId = model.FromId, DateOfSend = DateTime.Now }; this.requestForScrappingService.Add(request); //Add event that there is a new request this.eventService.AddForUserGroup(new Event { Content = "There is a new sccraping request for approving !", Date = DateTime.Now, EventRelocationUrl = "/AssetsActions/ScrappingAsset/RequestsForApproving" }, "Approve request for scrapping", this.userService.GetUserOrganisationId(this.User.Identity.GetUserId())); return(Redirect("/AssetsActions/ScrappingAsset/SuccessSend")); }
/// <summary> /// Add a new request for scrapping /// </summary> /// <param name="model"></param> public void Add(RequestForScrapping model) { this.context.RequestsForScrapping.Add(model); this.context.SaveChanges(); }