public ActionResult Edit(CompanyFileVM model) { if (model.CompanyFile == null) { model.CompanyFile = new CompanyFile(); } model.UploadFile = CompanyFiles.GetUploadFile(Request.Files[0]); if (!FluentValidate(model)) { return(RedirectBack()); } CompanyFile companyFile = null; if (model.CompanyFile.Name.IsEmpty()) { model.CompanyFile.Name = model.UploadFile.Name; } if (model.IsNew) { companyFile = model.CompanyFile; companyFile.UserID = User.UserID; companyFile.SysFileName = model.UploadFile.Name; CompanyFileService.InsertAndSubmit(companyFile); } else { var userFileId = model.CompanyFile.Id; companyFile = CompanyFileService.GetByPK(userFileId); if (companyFile.UserID != User.UserID) { throw new NotOwnerException("File"); } companyFile.Update(model.CompanyFile, x => x.Name, x => x.CompanyID); if (!model.UploadFile.IsEmpty) { companyFile.SysFileName = model.UploadFile.Name; } CompanyFileService.SubmitChanges(); } if (!model.UploadFile.IsEmpty) { CompanyFiles.DeleteFile(companyFile.Id); var hpf = Request.Files[0]; hpf.SaveAs(CompanyFiles.GetUserFileSys(companyFile.Id, model.UploadFile.Name)); } return(RedirectToAction(() => List())); }
public ActionResult Delete(int fileID) { var file = CompanyFileService.GetByPK(fileID); if (file.UserID != User.UserID) { throw new NotOwnerException("File"); } CompanyFileService.DeleteAndSubmit(file); CompanyFiles.DeleteFile(file.Id); return(RedirectBack()); }
public ActionResult Edit(int fileID) { var file = CompanyFileService.GetByPK(fileID); if (file.UserID != User.UserID) { throw new PermissionException("file edit"); } var model = new CompanyFileVM { CompanyFile = file, User = User }; InitModel(model); return(BaseView(Views.CompanyFile.Edit, model)); }