public ActionResult Delete(int? id) { WorkBl work = new WorkBl(); if (id != null) { work.Delete(int.Parse(id.ToString())); } return RedirectToAction("index"); }
public ActionResult Edit(int? id, string Title, string Description, string Url, int _WorkType, bool Live, HttpPostedFileBase[] BrowsePhotos) { if (ModelState.IsValid) { WorkBl work = new WorkBl(); int _id = id != null ? int.Parse(id.ToString()) : 0; //get currentwork if (_id > 0) { Work thisWork = work.GetById(_id); if (thisWork.User.Id != Assets.CurrentUser.Id) { TempData["Error"] = string.Format("Operation failed"); return RedirectToAction("index"); } } if(string.IsNullOrEmpty(Title) || string.IsNullOrEmpty(Description) || string.IsNullOrWhiteSpace(Title) || string.IsNullOrWhiteSpace(Description) ) { TempData["Error"] = string.Format("Operation failed"); return RedirectToAction("index"); } if (_WorkType == (int)WorkType.Websites && (string.IsNullOrEmpty(Url) || string.IsNullOrWhiteSpace(Url))) { TempData["Error"] = string.Format("Please add a url for this type of a project"); return RedirectToAction("index"); } //save Work _work = work.Save(_id, Title, Description, Url, (WorkType)_WorkType, Assets.CurrentUser.Id, DateTime.Now, true, false, Live, false, 1); if (BrowsePhotos != null) { foreach (HttpPostedFileBase file in BrowsePhotos) { if (file != null) { try { string ogFilePath = System.IO.Path.Combine(Server.MapPath(ImageFiles.SaveFilePath(Work.FolderPath))); file.SaveAs(ogFilePath); string filePath = ImageFiles.Resize(1000, 1000, ogFilePath, Work.FolderPath); string previewPath = ImageFiles.Resize(813, 500, ogFilePath, Work.FolderPath); string thumbPath = ImageFiles.Crop(216, 150, ogFilePath, Work.FolderPath); string iconPath = ImageFiles.Crop(50, 50, ogFilePath, Work.FolderPath); PhotoBl photo = new PhotoBl(); photo.Save(0, _work.Id, PhotoType.Work, filePath, previewPath, thumbPath, iconPath); //delete og file path when done in case its too big System.IO.File.Delete(ogFilePath); } catch { work.Delete(_work.Id); TempData["Error"] = string.Format("An error occured while processing your images. Make sure your images are in the correct format"); return RedirectToAction("index"); } } } } TempData["Success"] = string.Format("{0}, successfully saved", _work.Title); } return RedirectToAction("index"); }
public ActionResult Delete(int? id) { int _id = int.Parse(id.ToString()); WorkBl work = new WorkBl(); if (id != null) { //check if work belongs to user if (_id > 0) { Work thisWork = work.GetById(_id); if (thisWork.User.Id != Assets.CurrentUser.Id) { TempData["Error"] = string.Format("Operation failed"); return RedirectToAction("index"); } } //delete his/her work work.Delete(int.Parse(id.ToString())); } TempData["Success"] = "Project successfully deleted"; return RedirectToAction("index"); }