public OperationResult Create(CreateArticleCategory command) { var operation = new OperationResult(); if (_articleCategoryRepository.Exists(x => x.Name == command.Name)) { return(operation.Failed(ApplicationMessage.DuplicatedRecord)); } var slug = command.Slug.Slugify(); var pictureName = _fileUploader.Upload(command.Picture, slug); var articleCategory = new ArticleCategory(command.Name, pictureName, command.PictureAlt, command.PictureTitle, command.Description, command.ShowOrder, slug, command.Keywords, command.Description, command.CanonicalAddress); _articleCategoryRepository.Create(articleCategory); _articleCategoryRepository.SaveChanges(); return(operation.Succedded()); }
public UploadResult Upload(UploadFile file) { if (_globalSettings.DisableSite) { //网站关闭 } return(_fileUploader.Upload(file)); }
public async Task <ActionResult> AddEdit(BuildViewModel model) { bool response = false; var apiModel = new BuildModel { Name = model.Name, ChangeSet = model.ChangeSet, Release = model.Release, ProjectId = model.ProjectId, ProjectName = model.ProjectName }; #region Upload Files string directoryName = string.Format("{0}-{1}-{2}", model.ProjectName, model.Release, model.ChangeSet); foreach (var package in model.Packages) { var file = uploader.Upload(package, directoryName, Path.GetFileName(package.FileName)); apiModel.Packages.Add(new PackageModel { Name = file.Name, Path = file.Location }); } foreach (var script in model.Scripts) { var file = uploader.Upload(script, directoryName, Path.GetFileName(script.FileName)); apiModel.Scripts.Add(new SqlScriptModel { Name = file.Name, Extension = file.Extension, Path = file.Location }); } #endregion if (model.IsNew) { response = await ApiUtility.PostAsync <BuildModel>(Services.Builds, apiModel); } else { response = await ApiUtility.PutAsync <BuildModel>(Services.Builds, apiModel); } if (response) { return(RedirectToAction("List")); } return(View(model)); }
public OperationResult Register(RegisterAccount command) { var operation = new OperationResult(); if (_accountRepository.Exists(x => x.Username == command.Username || x.Mobile == command.Mobile)) { return(operation.Failed(ApplicationMessages.DuplicatedRecord)); } var password = _passwordHasher.Hash(command.Password); const string path = "ProfilePhotos"; var picturePath = _fileUploader.Upload(command.ProfilePhoto, path); var account = new Account(command.Fullname, command.Username, password, command.Mobile, command.RoleId, picturePath); _accountRepository.Create(account); _accountRepository.SaveChanges(); return(operation.Succeed()); }
public OperationResult Create(CreateProductPicture command) { var operation = new OperationResult(); //if (_productPictureRepository.Exist(x=> x.Id == command.ProductId)) //{ // return operation.Failed(ApplicationMessages.DuplicatedRecord); //} var product = _productRepository.GetProductWithCategory(command.ProductId); var picturePath = $"{"Shop"}/{"ProductCategory"}/{product.Category.Slug}/{product.Slug}/{command.PictureAlt}"; var fileName = _fileUploader.Upload(command.Picture, picturePath); var productPicture = new ProductPicture(command.ProductId, fileName, command.PictureAlt, command.PictureTitle); _productPictureRepository.Create(productPicture); _productPictureRepository.SaveChanges(); return(operation.Succedded()); }
public OperationResult Create(CreateProductCategory command) { var operation = new OperationResult(); if (_productCategoryRepository.Exist(x => x.Name == command.Name)) { return(operation.Failed(ApplicationMessages.DuplicatedRecord)); } var slug = command.Slug.Slugify(); var picturePath = $"{slug}"; var fileName = _fileUploader.Upload(command.Picture, picturePath); var productCategory = new ProductCategory(command.Name, command.Description, fileName, command.PictureTitle, command.PictureAlt, command.Keywords, command.MetaDescription, slug); _productCategoryRepository.Create(productCategory); _productCategoryRepository.SaveChanges(); return(operation.Succedded()); }
public OperationResult Create(CreateSponsor command) { var operation = new OperationResult(); if (_sponsorRepository.Exist(x => x.Name == command.Name)) { return(operation.Failed(ApplicationMessages.DuplicatedRecord)); } var ImageFolderName = Tools.ToFolderName(this.GetType().Name); var ImagePath = $"{ImageFolderName}/{command.Name}"; var imageFileName = _fileUploader.Upload(command.Image, ImagePath); var sponsor = new Sponsor(command.Name, command.Tel, imageFileName, command.ImageAlt, command.ImageTitle, command.IsVisible, command.Bio); _sponsorRepository.Create(sponsor); _sponsorRepository.SaveChanges(); return(operation.Succedded()); }
public OperationResult Create(CreateProductPicture command) { var operation = new OperationResult(); /* if (_productPictureRepository.Exists(x => x.Picture == command.Picture && x.ProductId == command.ProductId)) * return operation.Failed(ApplicationMessages.DuplicatedRecord); */ var product = _productRepository.GetProductWithCategory(command.ProductId); var path = $"{product.Category.Slug}//{product.Slug}"; var picturePath = _fileUploader.Upload(command.Picture, path); var produtPicture = new ProductPicture(command.ProductId, picturePath, command.PictureAlt, command.PictureTitle); _productPictureRepository.Create(produtPicture); _productPictureRepository.SaveChanges(); return(operation.Succedded()); }
public OperationResult Create(CreateProduct command) { var operation = new OperationResult(); if (_productRepository.Exists(x => x.Name == command.Name)) { return(operation.Failed(ApplicationMessages.DuplicatedRecord)); } var slug = command.Slug.Slugify(); var categorySlug = _productCategoryRepository.GetSlugById(command.CategoryId); var path = $"{categorySlug}//{slug}"; var picturePath = _fileUploader.Upload(command.Picture, path); var product = new Product(command.Name, command.Code, command.ShortDescription, command.ShortDescription, picturePath, command.PictureAlt, command.PictureTitle, slug, command.Keywords, command.MetaDescription, command.CategoryId); _productRepository.Create(product); _productRepository.SaveChanges(); return(operation.Succeed()); }
public OperationResult Create(CreateArticle command) { var operation = new OperationResult(); if (_articleRepository.Exists(x => x.Title == command.Title)) { return(operation.Failed(ApplicationMessage.DuplicatedRecord)); } var slug = command.Slug.Slugify(); var publishDate = command.PublishDate.ToGeorgianDateTime(); var categorySlug = _articleCategoryRepository.GetSlugBy(command.CategoryId); var path = $"{categorySlug}/{slug}"; var pictureName = _fileUploader.Upload(command.Picture, path); var article = new Article(command.Title, command.ShortDescription, command.Description, pictureName, command.PictureAlt, command.PictureTitle, publishDate, slug, command.MetaDescription, command.Keyword, command.CanonialAddress, command.CategoryId); _articleRepository.Create(article); _articleRepository.SaveChanges(); return(operation.Succedded()); }
public OperationResult Create(CreateMultimedia command, List <IFormFile> files) { var operation = new OperationResult(); if (_multimediaRepository.Exist(x => x.Title == command.Title)) { return(operation.Failed(ApplicationMessages.DuplicatedRecord)); } var ceremony = _ceremonyRepository.GetDetail(command.CeremonyId); foreach (var item in files) { var ImageFolderName = Tools.ToFolderName(this.GetType().Name); var ImagePath = $"{ImageFolderName}/{ceremony.Slug}"; var imageFileName = _fileUploader.Upload(item, ImagePath); var multimedia = new Multimedia(ceremony.Title, imageFileName, command.FileTitle, command.FileAlt, command.CeremonyId); _multimediaRepository.Create(multimedia); } _multimediaRepository.SaveChanges(); return(operation.Succedded()); }
public OperationResult Create(CreateGuest command) { var operation = new OperationResult(); if (_guestRepository.Exist(x => x.FullName == command.FullName)) { return(operation.Failed(ApplicationMessages.DuplicatedRecord)); } var slug = command.FullName.Slugify(); var ImageFolderName = Tools.ToFolderName(this.GetType().Name); var ImagePath = $"{ImageFolderName}/{slug}"; var imageFileName = _fileUploader.Upload(command.Image, ImagePath); var guest = new Guest(command.FullName, command.Tel, command.Email, imageFileName, command.ImageAlt, command.ImageTitle, command.GuestType, command.Coordinator); _guestRepository.Create(guest); _guestRepository.SaveChanges(); return(operation.Succedded()); }
public OperationResult Create(CreateCeremony command) { var operation = new OperationResult(); if (_ceremonyRepository.Exist(x => x.Title == command.Title)) { return(operation.Failed(ApplicationMessages.DuplicatedRecord)); } var slug = command.Slug.Slugify(); var ImageFolderName = Tools.ToFolderName(this.GetType().Name); var ImagePath = $"{ImageFolderName}/{command.Slug}"; var imageFileName = _fileUploader.Upload(command.Image, ImagePath); var bannerFileName = _fileUploader.Upload(command.BannerFile, ImagePath); ceremony = new Ceremony(command.Title, command.CeremonyDate.ToGeorgianDateTime(), command.IsLive, bannerFileName, imageFileName, command.ImageAlt, command.ImageTitle, command.Keywords, command.MetaDescription, slug); CreateOperationLog(ceremony.Id, 1); _ceremonyRepository.Create(ceremony); _ceremonyRepository.SaveChanges(); return(operation.Succedded()); }
public virtual ActionResult EnterAcademicDetails(AcademicDetailModel academicDetailModel, int id) { if (!ModelState.IsValid) { return(View(academicDetailModel)); } var fileCategory = ((int)academicDetailModel.SchoolYear).ToString(CultureInfo.InvariantCulture); var performanceHistoryFileName = _fileUploader.Upload(academicDetailModel.PerformanceHistoryFile, id, fileCategory, "performanceHistory"); var studentAcademicDetail = _academicDetailMapper.Build(academicDetailModel, adm => { adm.StudentUSI = id; adm.PerformanceHistoryFile = performanceHistoryFileName; }); var studentSchoolAssociation = _schoolAssociationMapper.Build(academicDetailModel); _repository.Add(studentAcademicDetail); _repository.Add(studentSchoolAssociation); _repository.Save(); return(RedirectToAction(MVC.Enrollment.EnterProgramStatus(id))); }
public OperationResult Create(CreateArticle command) { OperationResult operationResult = new OperationResult(); if (_articleRepo.Exists(c => c.Title == command.Title)) { return(operationResult.Failed(ApplicationMessage.duplicated)); } var slug = command.Slug.Slugify(); var categorySlug = _articleCategoryRepo.GetSlugBy(command.CategoryId); var path = $"{categorySlug}/{slug}"; var PicName = _fileUploader.Upload(command.Picture, path); var Article = new Article(command.Title, command.ShortDescription, command.Description, PicName , command.PictureAlt, command.Title, slug, command.KeyWords, command.MetaDescription, command.CanonicalAddress, command.PublishDate.ToGeorgianDateTime(), command.CategoryId); _articleRepo.Create(Article); _articleRepo.Save(); return(operationResult.Succeeded()); }
public IActionResult Index(UploadModel model) { var member = _workContext.CurrentMember; if (member == null) { throw new AlertException("未登录"); } var uploadResult = _fileManager.Upload(new UploadFile() { FormFile = model.File }); return(Json(uploadResult)); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (ProductModel.ImageFile != null && ProductModel.ImageFile.Length > 0) { ProductModel.ImageUrl = await _fileUploader.Upload(ProductModel.ImageFile, "products"); } _dbContext.Add(ProductModel.ToEntity()); await _dbContext.SaveChangesAsync(); return(RedirectToPage("Index")); }
public virtual async Task <IActionResult> UploadAvatar(IFormFile avatar, string id) { if (!await CheckAvatarId(id)) { return(Json(JsonError.ERROR_ACCESS_DENIED)); } if ((avatar.FileName.ToLower().EndsWith(".png")) || (avatar.FileName.ToLower().EndsWith(".jpg"))) { // int userId = int.Parse(_mngr.GetUserId(User)); string fname = $"{AvatarName}_{id}_avatar" + avatar.FileName.Substring(avatar.FileName.LastIndexOf('.')); await _fileUploader.Upload(fname, avatar); return(Json(new { Status = "Ok", Url = Url.Action("TempAvatar", new { name = fname }) })); } return(Json(JsonError.ERROR_FORMAT_NOT_SUP)); }
public async Task <IActionResult> Create([FromForm] PostViewModel post, IFormFile formFile) { if (ModelState.IsValid) { ApplicationUser currentUser = await userManager.FindByNameAsync(User.Identity.Name); post.Author = currentUser; if (formFile != null && formFile.Length > 0) { string userMediaPath = Path.Combine(new[] { env.WebRootPath, "media", "user", currentUser.Id + Path.DirectorySeparatorChar }); UploadableImageFile file = fileUploader.NewUploadableImageFile(); file.FormFile = formFile; file.Directory = userMediaPath; file.Name = Guid.NewGuid().ToString(); file.MaxWidth = 1920; file.MaxHeight = 1080; file.HasThumbnail = true; file.ThumbWidth = 512; file.ThumbHeight = 512; await fileUploader.Upload(file); post.Attachment = new AttachmentViewModel { Owner = currentUser, Type = FileType.image.ToString(), Name = file.Name, Extension = file.Extension, }; } repository.AddPost(post); return(Ok()); } else { return(BadRequest()); } }
public async Task <Response> Process(Request request, CancellationToken cancellationToken = default) { var stopwatch = Stopwatch.StartNew(); var files = await fileRetriever.RetrieveToMemory(request.OriginBucketName, request.OriginResourceName, request.OriginResourceExpressionPattern, cancellationToken); log.Debug("Retrieved files from {Bucket}:{Resource} | {Time}ms", request.OriginBucketName, request.OriginResourceName, stopwatch.ElapsedMilliseconds); stopwatch.Restart(); var compressedFile = await fileZipper.Compress(request.DestinationResourceName, files, request.FlatZipFile, cancellationToken); log.Debug("Compressed files to {CompressedFileName} | {Time}ms", compressedFile.ResourceKey, stopwatch.ElapsedMilliseconds); stopwatch.Restart(); var url = await fileUploader.Upload(request.DestinationBucketName, request.DestinationResourceName, compressedFile, cancellationToken); log.Debug("Uploaded file to {Url} | {Time}ms", url, stopwatch.ElapsedMilliseconds); return(new Response(url)); }
public ResultHelperModel Create(int userId, CreateTweetDto dto) { var result = new ResultHelperModel { Success = true, Message = string.Empty }; var userProfile = _baseRepository.Get <UserProfile>(x => x.UserId == userId); var tweet = _mapper.Map <Tweet>(dto); tweet.UserProfile = userProfile; tweet.AddedDate = DateTime.Now; if (!string.IsNullOrEmpty(dto.Photo)) { try { tweet.Photo = _fileUploader.Upload(dto.Photo); } catch (Exception ex) { result.Success = false; result.Message = ex.Message; return(result); } } try { _baseRepository.Create(tweet); } catch (Exception ex) { result.Success = false; result.Message = ex.Message; return(result); } return(result); }
public OperationResult Create(CreateBasicInfo command) { var operation = new OperationResult(); var persianResume = _fileUploader.Upload(command.PersianResume, "PersianResume"); var englishResume = _fileUploader.Upload(command.EnglishResume, "EnglishResume"); var recommendationLetter = _fileUploader.Upload(command.RecommendationLetters, "RecommendationLetters"); var basicInfo = new BasicInformation(command.Name, command.Family, command.Age, command.Nationality, command.Job, command.Address, command.Email, command.Mobile, command.Instagram, command.Language, command.Experience, command.CompleteProject, command.HappyCustomers, command.Articles, persianResume, englishResume, recommendationLetter); _basicInfoRepository.Create(basicInfo); _basicInfoRepository.SaveChanges(); return(operation.Succedded()); }
public OperationResult Create(CreateProject command) { var operation = new OperationResult(); if (_projectRepository.Exist(x => x.Name == command.Name)) { return(operation.Failed(ApplicationMessages.DuplicatedRecord)); } var slug = command.Slug.Slugify(); var picturePath = $"{"Project"}/{slug}"; var firstPicture = _fileUploader.Upload(command.FirstPicture, picturePath); var secondPicture = _fileUploader.Upload(command.SecondPicture, picturePath); var thirdPicture = _fileUploader.Upload(command.ThirdPicture, picturePath); var forthPicture = _fileUploader.Upload(command.ForthPicture, picturePath); var project = new Project(command.Name, command.Customer, command.Technology, firstPicture, secondPicture, thirdPicture, forthPicture, command.PictureAlt, command.PictureTitle, command.Slug, command.UrlLink, command.CategoryId, command.Description); _projectRepository.Create(project); _projectRepository.SaveChanges(); return(operation.Succedded()); }
public void Upload(FileUploadSpec spec) { Wrap(() => _uploader.Upload(spec), spec); }
public static void Upload(this IFileUploader uploader, IAbsoluteFilePath localFile, Uri uri) { uploader.Upload(new FileUploadSpec(localFile, uri)); }
public static void Upload(this IFileUploader uploader, IAbsoluteFilePath localFile, Uri uri, ITransferProgress progress) { uploader.Upload(new FileUploadSpec(localFile, uri, progress)); }
public void Add() { _uploader.Upload(); Console.WriteLine("Person added."); }
public static void Upload(this IFileUploader uploader, IAbsoluteFilePath localFile, string url) { uploader.Upload(new FileUploadSpec(localFile, url)); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var user = await userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{userManager.GetUserId(User)}'.")); } if (Input.Name != user.Name) { user.Name = Input.Name; } if (Input.Description != user.Description) { user.Description = Input.Description; } if (Input.Location != user.Location) { user.Location = Input.Location; } if (Input.Website != user.Website) { user.Website = Input.Website; } if (HttpContext.Request.Form.Files.Count > 0) { string userMediaPath = Path.Combine(new[] { env.WebRootPath, "media", "user", user.Id + Path.DirectorySeparatorChar }); var files = new List <UploadableFile>(); if (Input.Avatar != null && Input.Avatar.Length > 0) { UploadableImageFile file = fileUploader.NewUploadableImageFile(); file.FormFile = Input.Avatar; file.Directory = userMediaPath; file.Name = Guid.NewGuid().ToString(); file.MaxWidth = 512; file.MaxHeight = 512; files.Add(file); if (user.AvatarImage != null) { System.IO.File.Delete(userMediaPath + user.AvatarImage); } user.AvatarImage = file.Name + "." + file.Extension; } if (Input.Cover != null && Input.Cover.Length > 0) { UploadableImageFile file = fileUploader.NewUploadableImageFile(); file.FormFile = Input.Cover; file.Directory = userMediaPath; file.Name = Guid.NewGuid().ToString(); file.MaxWidth = 1920; file.MaxHeight = 1080; files.Add(file); if (user.CoverImage != null) { System.IO.File.Delete(userMediaPath + user.CoverImage); } user.CoverImage = file.Name + "." + file.Extension; } await fileUploader.Upload(files); } await userManager.UpdateAsync(user); await signInManager.RefreshSignInAsync(user); StatusMessage = "Your profile has been updated"; return(RedirectToPage()); }