public UploadFormViewModel EditUploadForm(int itemId) { string emailAddress = HttpContext.Current.User.Identity.Name.ToString(); if (!global.IsUniqueEmailAddress(emailAddress)) { Account userAccount = global.GetAccount(emailAddress); Item referenceItem = (userAccount != null) ? db.Item.Where(i => i.ItemId == itemId && i.AccountId == userAccount.AccountId).FirstOrDefault() : null; if (referenceItem != null) { UploadFormViewModel newForm = new UploadFormViewModel(); newForm.Name = referenceItem.Name; newForm.Caption = referenceItem.Caption; newForm.Description = referenceItem.Description; Image itemImage = imaging.ServeImage(referenceItem); if (itemImage != null) { newForm.ImageString = itemImage.ImageSource; newForm.ImageKeep = 1; } newForm.CategoriesList = global.GetCategoryList(); if (newForm.CategoriesList == null) { return(null); } newForm.SubcategoriesList = global.GetSubCategoryList(); newForm.ReferenceAction = "Edit"; newForm.ReferenceId = itemId; return(newForm); } } return(null); }
public ActionResult Edit(UploadFormViewModel postForm) { var validationOutputs = new string[0]; bool validForm = uploadManager.ValidateUploadForm(postForm, out validationOutputs); if (validForm) { string responseMessage; postForm.ReferenceId = int.Parse(Session["reference"].ToString()); bool editItem = uploadManager.EditUploadItem(postForm, out responseMessage); if (editItem) { Session["updateMessage"] = responseMessage; return(RedirectToAction("Index", "Items")); } else { Session["updateMessage"] = new string[] { responseMessage }; return(RedirectToAction("Edit", "Items", new { reference = int.Parse(Session["reference"].ToString()) })); } } else { Session["updateMessage"] = validationOutputs; return(RedirectToAction("Edit", "Items", new { reference = int.Parse(Session["reference"].ToString()) })); } }
public ActionResult Upload(UploadFormViewModel postForm) { var validationOutputs = new string[0]; bool validForm = uploadManager.ValidateUploadForm(postForm, out validationOutputs); if (validForm) { string responseMessage; bool addItem = uploadManager.CreateUploadItem(postForm, out responseMessage); if (addItem) { Session["updateMessage"] = responseMessage; return(RedirectToAction("Index", "Items")); } else { Session["updateMessage"] = new string[] { responseMessage }; return(RedirectToAction("Upload", "Items")); } } else { Session["updateMessage"] = validationOutputs; return(RedirectToAction("Upload", "Items")); } }
public async Task <IActionResult> UploadFiles([FromForm] UploadFormViewModel viewModel) { if (!ModelState.IsValid) { return(viewModel.DirectoryId == null ? (IActionResult)View(!viewModel.IsPrivate ? "Public" : "Private", storageViewModel) : View("Directory", directoryViewModel.SetPrivate(viewModel.IsPrivate))); } return(await storageManager.UploadFiles(viewModel.Files, directoryId : viewModel.DirectoryId, isPrivate : viewModel.IsPrivate) ? (viewModel.DirectoryId == null ? (IActionResult)RedirectToAction(!viewModel.IsPrivate ? "Public" : "Private") : RedirectToAction("Directory", new { id = viewModel.DirectoryId, isPrivate = viewModel.IsPrivate })).PushAlert("File has been uploaded") : (viewModel.DirectoryId == null ? (IActionResult)RedirectToAction(!viewModel.IsPrivate ? "Public" : "Private") : RedirectToAction("Directory", new { id = viewModel.DirectoryId, isPrivate = viewModel.IsPrivate }))); }
public bool EditUploadItem(UploadFormViewModel editForm, out string outputMessage) { string emailAddress = HttpContext.Current.User.Identity.Name.ToString(); Account userAccount = global.GetAccount(emailAddress); try { Item referenceItem = db.Item.Where(i => i.ItemId == editForm.ReferenceId && i.AccountId == userAccount.AccountId).FirstOrDefault(); if (referenceItem != null) { referenceItem.Name = editForm.Name; referenceItem.Caption = editForm.Caption; referenceItem.Description = editForm.Description; referenceItem.CategoryId = editForm.ItemCategory; referenceItem.SubcategoryId = editForm.ItemSubcategory; referenceItem.TradeCategoryId = editForm.TradeCategory; referenceItem.TradeSubcategoryId = editForm.TradeSubcategory; db.SaveChanges(); if (editForm.ImageKeep != 0) { if (editForm.ImageUpload != null) { imaging.DeleteImage(referenceItem.ItemId); Image uploadImage = imaging.AddImage(editForm.ImageUpload, referenceItem); } } else { imaging.DeleteImage(referenceItem.ItemId); } outputMessage = editForm.Name + " has been updated."; RedirectViewModel redirect = new RedirectViewModel("Details", "Items", referenceItem.ItemId.ToString()); SaveNotification(referenceItem, redirect, NotificationType.EditItem); return(true); } else { outputMessage = Resources.Processing.ProcessError; return(false); } } catch { outputMessage = Resources.Processing.ProcessError; return(false); } }
public ActionResult Upload() { UploadFormViewModel newForm = uploadManager.NewUploadForm(); if (Session["updateMessage"] != null) { var postMessage = Session["updateMessage"]; Session.Remove("updateMessage"); ViewBag.Collection = postMessage; } if (uploadManager.isItemCollectionFull()) { Session["errorMessage"] = Resources.Processing.ProcessMaxItems; return(RedirectToAction("Index", "Items")); } return(View(newForm)); }
public UploadFormViewModel NewUploadForm() { string emailAddress = HttpContext.Current.User.Identity.Name.ToString(); if (!global.IsUniqueEmailAddress(emailAddress)) { UploadFormViewModel newForm = new UploadFormViewModel(); newForm.CategoriesList = global.GetCategoryList(); if (newForm.CategoriesList == null) { return(null); } newForm.SubcategoriesList = global.GetSubCategoryList(); newForm.ReferenceAction = "Upload"; newForm.ReferenceId = 0; return(newForm); } return(null); }
public bool CreateUploadItem(UploadFormViewModel newForm, out string outputMessage) { string emailAddress = HttpContext.Current.User.Identity.Name.ToString(); Account userAccount = global.GetAccount(emailAddress); try { Item uploadItem = new Item(); uploadItem.AccountId = userAccount.AccountId; uploadItem.Name = newForm.Name; uploadItem.Caption = newForm.Caption; uploadItem.Description = newForm.Description; uploadItem.CategoryId = newForm.ItemCategory; uploadItem.SubcategoryId = newForm.ItemSubcategory; uploadItem.TradeCategoryId = newForm.TradeCategory; uploadItem.TradeSubcategoryId = newForm.TradeSubcategory; db.Item.Add(uploadItem); db.SaveChanges(); ItemDetail uploadItemDetail = new ItemDetail(); uploadItemDetail.ItemId = uploadItem.ItemId; uploadItemDetail.ItemStatus = 1; uploadItemDetail.Reported = 0; uploadItemDetail.UploadDate = DateTime.Now; db.ItemDetail.Add(uploadItemDetail); db.SaveChanges(); if (newForm.ImageUpload != null) { Image uploadImage = imaging.AddImage(newForm.ImageUpload, uploadItem); } RedirectViewModel redirect = new RedirectViewModel("Details", "Items", uploadItem.ItemId.ToString()); SaveNotification(uploadItem, redirect, NotificationType.AddItem); outputMessage = newForm.Name + " has been added to your items."; return(true); } catch { outputMessage = Resources.Processing.ProcessError; return(false); } }
public ActionResult Edit(int reference) { UploadFormViewModel newForm = uploadManager.EditUploadForm(reference); if (Session["reference"] != null) { Session.Remove("reference"); } if (Session["updateMessage"] != null) { var postMessage = Session["updateMessage"]; Session.Remove("updateMessage"); ViewBag.Collection = postMessage; } if (newForm == null) { Session["errorMessage"] = Resources.Processing.ProcessEditNoForm; return(RedirectToAction("Index", "Items")); } Session["reference"] = reference; return(View("Upload", newForm)); }
public bool ValidateUploadForm(UploadFormViewModel newForm, out string[] outputMessages) { bool flag = true; List <string> outputs = new List <string>(); string emailAddress = HttpContext.Current.User.Identity.Name.ToString(); Account userAccount = global.GetAccount(emailAddress); if (string.IsNullOrWhiteSpace(newForm.Name)) { flag = false; outputs.Add("The title of your upload cannot be blank"); } if (string.IsNullOrWhiteSpace(newForm.Caption)) { flag = false; outputs.Add("The caption of your item cannot be blank"); } if (string.IsNullOrWhiteSpace(newForm.Description)) { flag = false; outputs.Add("The description of your item cannot be blank"); } if (newForm.ItemCategory == 0) { flag = false; outputs.Add("The category of your item cannot be set to 'All / Anything'"); } if (newForm.ItemCategory == 0) { flag = false; outputs.Add("The subcategory of your item cannot be set to 'All / Anything'"); } outputMessages = outputs.ToArray(); return(flag); }
public IViewComponentResult Invoke(UploadFormViewModel viewModel) => View(viewModel);