コード例 #1
0
ファイル: CompanyFileController.cs プロジェクト: dKluev/Site
        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()));
        }
コード例 #2
0
ファイル: CompanyFileController.cs プロジェクト: dKluev/Site
        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());
        }
コード例 #3
0
        public IActionResult UpdateCompanyLogo([FromBody] CompanyFiles companyFiles)
        {
            Dictionary <string, object> res;

            try
            {
                res = Service.createSuccessRes();
                res.Add("Updated", CompanyData.UpdateCompanyLogo(companyFiles, _appEnvironment));
                return(Ok(res));
            }
            catch (System.Exception ex)
            {
                res = Service.createErrorRes(ex.Message);
                return(BadRequest(res));
            }
        }
コード例 #4
0
 public override object Get()
 {
     if (!Model.CompanyFiles.Any())
     {
         return(p["Пока ничего нет"]);
     }
     return(div[H.table.Class("table")[H.Head("Дата", "Файл", ""),
                                       Model.CompanyFiles.Select(x => H.Row(
                                                                     x.CreateDate.DefaultString(), x.Name, H.Anchor(CompanyFiles.GetFileUrl(x.Id), "Скачать")))]]);
 }