public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StockStandard stockstandard = _uow.StockStandardRepository.Get(id); if (stockstandard == null) { return(HttpNotFound()); } StockStandardEditViewModel model = new StockStandardEditViewModel() { StockStandardId = stockstandard.StockStandardId, LotNumber = stockstandard.LotNumber, StockStandardName = stockstandard.StockStandardName, IdCode = stockstandard.IdCode, DateCreated = stockstandard.DateCreated, ExpiryDate = stockstandard.ExpiryDate, CertificateOfAnalysis = stockstandard.InventoryItems.Where(x => x.StockStandard.StockStandardId == stockstandard.StockStandardId).Select(x => x.CertificatesOfAnalysis.OrderBy(y => y.DateAdded).First()).First(), MSDS = stockstandard.InventoryItems.Where(x => x.StockStandard.StockStandardId == stockstandard.StockStandardId).Select(x => x.MSDS.OrderBy(y => y.DateAdded).First()).First() }; foreach (var item in stockstandard.InventoryItems) { model.SupplierName = item.SupplierName; } return(View(model)); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StockStandard standard = _uow.StockStandardRepository.Get(id); if (standard == null) { return(HttpNotFound("The standard requested does not exist.")); } if (Request.UrlReferrer.AbsolutePath.Contains("IntermediateStandard")) { ViewBag.ReturnUrl = Request.UrlReferrer.AbsolutePath; } StockStandardDetailsViewModel vStandard = new StockStandardDetailsViewModel() { StockStandardId = standard.StockStandardId, LotNumber = standard.LotNumber, IdCode = standard.IdCode, StockStandardName = standard.StockStandardName, LastModifiedBy = standard.LastModifiedBy, SolventUsed = standard.SolventUsed, Concentration = standard.Concentration, Purity = standard.Purity, ExpiryDate = standard.ExpiryDate, DateOpened = standard.DateOpened, DateCreated = standard.DateCreated, CreatedBy = standard.CreatedBy, DateModified = standard.DateModified, DateReceived = standard.DateReceived }; foreach (var invItem in standard.InventoryItems) { if (invItem.StockStandard.StockStandardId == standard.StockStandardId) { vStandard.CertificateOfAnalysis = invItem.CertificatesOfAnalysis.OrderByDescending(x => x.DateAdded).Where(x => x.InventoryItem.InventoryItemId == invItem.InventoryItemId).First(); vStandard.MSDS = invItem.MSDS.Where(x => x.InventoryItem.InventoryItemId == invItem.InventoryItemId).First(); vStandard.UsedFor = invItem.UsedFor; vStandard.Department = invItem.Department; vStandard.CatalogueCode = invItem.CatalogueCode; vStandard.AllCertificatesOfAnalysis = invItem.CertificatesOfAnalysis.OrderByDescending(x => x.DateAdded).Where(x => x.InventoryItem.InventoryItemId == invItem.InventoryItemId).ToList(); vStandard.MSDSNotes = invItem.MSDS.Where(x => x.InventoryItem.InventoryItemId == invItem.InventoryItemId).First().MSDSNotes; vStandard.SupplierName = invItem.SupplierName; vStandard.IsExpired = invItem.StockStandard.ExpiryDate < DateTime.Today; vStandard.IsExpiring = invItem.StockStandard.ExpiryDate < DateTime.Today.AddDays(30) && !(invItem.StockStandard.ExpiryDate < DateTime.Today); vStandard.NumberOfBottles = invItem.NumberOfBottles; vStandard.InitialAmount = invItem.InitialAmount; } } return(View(vStandard)); }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StockStandard stockstandard = _uow.StockStandardRepository.Get(id); if (stockstandard == null) { return(HttpNotFound()); } return(View(stockstandard)); }
public static CheckModelState EnterStandardIntoDatabase(StockStandardCreateViewModel model, InventoryItem inventoryItem, int numOfItems, Department department, string user, UnitOfWork _uow) { CheckModelState result = CheckModelState.Invalid;//default to invalid to expect the worst var repo = _uow.StockStandardRepository; StockStandard createStandard = new StockStandard() { LotNumber = model.LotNumber, StockStandardName = model.StockStandardName, Purity = model.Purity, SolventUsed = model.SolventUsed, Concentration = model.Concentration.ToString() + " " + model.InitialConcentrationUnits, DateReceived = model.DateReceived, DateCreated = DateTime.Today, DateOpened = null, DaysUntilExpired = model.DaysUntilExpired, ExpiryDate = model.ExpiryDate, CreatedBy = user, DateModified = null, CatalogueCode = model.CatalogueCode.ToUpper() }; if (model.NumberOfBottles > 1) { //for (int i = 1; i <= model.NumberOfBottles; i++) { createStandard.IdCode = department.Location.LocationCode + "-" + (numOfItems + 1) + "-" + model.LotNumber + "/" + model.NumberOfBottles; //append number of bottles createStandard.InventoryItems.Add(inventoryItem); repo.Create(createStandard); result = _uow.Commit(); //creation wasn't successful - break from loop and let switch statement handle the problem //if (result != CheckModelState.Valid) { break; } //} } else { createStandard.IdCode = department.Location.LocationCode + "-" + (numOfItems + 1) + "-" + model.LotNumber + "/" + model.NumberOfBottles;//only 1 bottle, no need to concatenate createStandard.InventoryItems.Add(inventoryItem); repo.Create(createStandard); result = _uow.Commit(); } return(result); }
public ActionResult Edit([Bind(Include = "LotNumber,StockStandardId,ExpiryDate,IdCode,SupplierName,StockStandardName")] StockStandardEditViewModel stockstandard, HttpPostedFileBase uploadCofA, HttpPostedFileBase uploadMSDS) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { InventoryItemRepository inventoryRepo = _uow.InventoryItemRepository; var user = _uow.GetCurrentUser(); InventoryItem invItem = inventoryRepo.Get() .Where(item => item.StockStandard != null && item.StockStandard.StockStandardId == stockstandard.StockStandardId) .FirstOrDefault(); StockStandard updateStandard = invItem.StockStandard; updateStandard.StockStandardName = stockstandard.StockStandardName; updateStandard.IdCode = stockstandard.IdCode; updateStandard.LotNumber = stockstandard.LotNumber; updateStandard.LastModifiedBy = user.UserName; updateStandard.DateModified = DateTime.Today; updateStandard.ExpiryDate = stockstandard.ExpiryDate; _uow.StockStandardRepository.Update(updateStandard); //_uow.Commit(); if (uploadCofA != null) { var cofa = new CertificateOfAnalysis() { FileName = uploadCofA.FileName, ContentType = uploadCofA.ContentType, DateAdded = DateTime.Today }; using (var reader = new System.IO.BinaryReader(uploadCofA.InputStream)) { cofa.Content = reader.ReadBytes(uploadCofA.ContentLength); } stockstandard.CertificateOfAnalysis = cofa; //add certificate analysis invItem.CertificatesOfAnalysis.Add(cofa); } if (uploadMSDS != null) { var msds = new MSDS() { FileName = uploadMSDS.FileName, ContentType = uploadMSDS.ContentType, DateAdded = DateTime.Today }; using (var reader = new System.IO.BinaryReader(uploadMSDS.InputStream)) { msds.Content = reader.ReadBytes(uploadMSDS.ContentLength); } stockstandard.MSDS = msds; var msdsRepo = new MSDSRepository(); var oldSDS = msdsRepo.Get() .Where(item => item.InventoryItem.StockStandard != null && item.InventoryItem.StockStandard.StockStandardId == stockstandard.StockStandardId) .First(); oldSDS.Content = msds.Content; oldSDS.FileName = msds.FileName; oldSDS.ContentType = msds.ContentType; oldSDS.DateAdded = DateTime.Today; msdsRepo.Update(oldSDS); _uow.Commit(); } invItem.SupplierName = stockstandard.SupplierName; inventoryRepo.Update(invItem); //_uow.Commit(); return(RedirectToAction("Details", new { id = stockstandard.StockStandardId })); } return(View(stockstandard)); }
public ActionResult Create([Bind(Include = "StockStandardName,SupplierName,CatalogueCode,StorageRequirements,MSDSNotes,LotNumber,MSDSNotes,UsedFor,SolventUsed,Purity,ExpiryDate,NumberOfBottles,InitialAmount,Concentration,DateReceived,IsExpiryDateBasedOnDays,DaysUntilExpired,OtherUnitExplained,ConcentrationOtherUnitExplained")] StockStandardCreateViewModel model, string[] AmountUnit, string[] ConcentrationUnit, HttpPostedFileBase uploadCofA, HttpPostedFileBase uploadMSDS, string submit) { //model isn't valid, return to the form if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(v => v.Errors); return(View(SetStockStandard(model))); } var inventoryRepository = _uow.InventoryItemRepository; //catalogue code must be unique - let's verify bool doesCatalogueCodeExist = inventoryRepository.Get() .Any(item => item.CatalogueCode != null && item.CatalogueCode.Equals(model.CatalogueCode)); if (doesCatalogueCodeExist) { ModelState.AddModelError("", "The Catalogue Code provided is not unique. If the Catalogue Code provided is in fact correct, add the item as a new Lot Number under the existing Catalogue Code."); return(View(SetStockStandard(model))); } var devicesUsed = Request.Form["Devices"]; var user = _uow.GetCurrentUser(); var department = _uow.GetUserDepartment(); var numOfItems = inventoryRepository.Get().Count(); if (devicesUsed == null) { ModelState.AddModelError("", "You must select a device that was used."); return(View(SetStockStandard(model))); } model = BuildReagentOrStandard.BuildStandard(model, devicesUsed, AmountUnit, ConcentrationUnit, uploadCofA, uploadMSDS, _uow); InventoryItem inventoryItem = BuildReagentOrStandard.BuildStandardInventoryItem(model, department); StockStandard createStandard = null; CheckModelState result = BuildReagentOrStandard.EnterStandardIntoDatabase(model, inventoryItem, numOfItems, department, user.UserName, _uow); switch (result) { case CheckModelState.Invalid: ModelState.AddModelError("", "The creation of " + createStandard.StockStandardName + " failed. Please double check all inputs and try again."); return(View(SetStockStandard(model))); case CheckModelState.DataError: ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists please contact your system administrator."); return(View(SetStockStandard(model))); case CheckModelState.Error: ModelState.AddModelError("", "There was an error. Please try again."); return(View(SetStockStandard(model))); case CheckModelState.Valid: if (!string.IsNullOrEmpty(submit) && submit.Equals("Save")) { //save pressed return(RedirectToAction("Index")); } else { //save & new pressed return(RedirectToAction("Create")); } default: ModelState.AddModelError("", "An unknown error occurred."); return(View(SetStockStandard(model))); } }