public async Task <BaseModel> SaveAsync(ArticleViewModel model, IFormFile articleShareDocument) { try { //save with attcahed doc BaseModel baseModel = new BaseModel(); string articeDocUrl = string.Empty; string articleFolderPath = "ArcticlesShareDocuments/" + DateTime.Now.Year.ToString(); string articleFileName = string.Empty; if (articleShareDocument != null && articleShareDocument.Length > 0) { articleFileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(articleShareDocument.FileName); articeDocUrl = articleFolderPath + "/" + articleFileName; model.ShareDocument = articeDocUrl; } if (model.Id == 0) { UsersLoginDataModel _user = await _unitOfWork.UserLoginRepository.GetByID(model.UserId); CommunityGroupsDataModel communityGroupsData = await _unitOfWork.UserCommunityGroupsRepository.GetByID(model.CommunityGroupsId); baseModel = await Save(model, _user, communityGroupsData); } else { baseModel = await Update(model); } if (baseModel.Status == true) { if (articleShareDocument != null && articleShareDocument.Length > 0) { await _awsS3Bucket.UploadFileAsync(articleFolderPath, articleShareDocument, articleFileName); } } return(baseModel); } catch (Exception) { return(new BaseModel { Status = false, Messsage = UMessagesInfo.Error }); } }
public async Task <BaseModel> SaveAsync(CommunityTypeViewModel model, IFormFile articleShareDocument) { try { //save with attcahed doc string articeDocUrl = string.Empty; string articleFolderPath = "CommunityTypes/" + DateTime.Now.Year.ToString(); string articleFileName = string.Empty; if (articleShareDocument != null && articleShareDocument.Length > 0) { articleFileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(articleShareDocument.FileName); articeDocUrl = articleFolderPath + "/" + articleFileName; //model.ImageUrl = articeDocUrl; } if (model.Id == 0) { CommunityDataModel communityData = new CommunityDataModel(); if (articleShareDocument != null && articleShareDocument.Length > 0) { await _awsS3Bucket.UploadFileAsync(articleFolderPath, articleShareDocument, articleFileName); communityData.ImageUrl = articeDocUrl; } communityData.Name = model.Name; communityData.Description = model.Description; communityData.IsActive = model.IsActive; communityData.Color = model.Color; communityData.FooterLinkText = model.FooterLinkText; communityData.DisplayIndex = model.DisplayIndex; communityData.CommunityUrl = Urlhelper.GenerateSeoFriendlyURL(model.Name); // communityData.CommunityUrl = model.CommunityUrl; await _unitOfWork.CommunityRepository.Insert(communityData); } else { CommunityDataModel communityData = await _unitOfWork.CommunityRepository.GetByID(Convert.ToInt32(model.Id)); if (articleShareDocument != null && articleShareDocument.Length > 0) { //first delete old file await _awsS3Bucket.DeleteFileAsync(communityData.ImageUrl); await _awsS3Bucket.UploadFileAsync(articleFolderPath, articleShareDocument, articleFileName); communityData.ImageUrl = articeDocUrl; } communityData.Name = model.Name; communityData.Description = model.Description; communityData.IsActive = model.IsActive; communityData.Color = model.Color; communityData.FooterLinkText = model.FooterLinkText; communityData.DisplayIndex = model.DisplayIndex; communityData.CommunityUrl = Urlhelper.GenerateSeoFriendlyURL(model.Name); await _unitOfWork.CommunityRepository.Update(communityData); //baseModel = await Update(model); } return(new BaseModel { Status = true, Messsage = UMessagesInfo.RecordSaved }); } catch (Exception) { return(new BaseModel { Status = false, Messsage = UMessagesInfo.Error }); } }
public async Task <BaseModel> SaveAsync(CommunityGroupViewModel model, IFormFile file, IFormFile aticleSharedoc) { BaseModel baseModel = new BaseModel(); string articeDocUrl = string.Empty; var userData = await _unitOfWork.UserLoginRepository.GetByID(model.UserId); if (userData == null) { return(new BaseModel { Status = false, Messsage = UMessagesInfo.Error }); } try { if (file != null && file.Length > 0) { string folderPath = "CommunityGroups/" + DateTime.Now.Year.ToString(); string fileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file.FileName); string articleFolderPath = "ArcticlesShareDocuments/" + DateTime.Now.Year.ToString(); string articleFileName = string.Empty; if (file.Length > 0) { model.DescriptionVideoUrl = folderPath + "/" + fileName; } if (aticleSharedoc != null && aticleSharedoc.Length > 0) { articleFileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(aticleSharedoc.FileName); articeDocUrl = articleFolderPath + "/" + articleFileName; } if (model.Id == 0) //insert record { baseModel = await Save(model, userData, articeDocUrl); } else //update record { baseModel = await Update(model); } if (baseModel.Status == true) { if (file.Length > 0) { await _awsS3Bucket.UploadFileAsync(folderPath, file, fileName); } if (aticleSharedoc != null && aticleSharedoc.Length > 0) { await _awsS3Bucket.UploadFileAsync(articleFolderPath, aticleSharedoc, articleFileName); } } return(baseModel); } ///record insert without video file else { if (model.Id == 0) //insert record { return(await Save(model, userData, articeDocUrl)); } else //update record { model.DescriptionVideoUrl = ""; return(await Update(model)); } } } catch (Exception ex) { return(new BaseModel { Status = false, Messsage = UMessagesInfo.Error }); } }