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 }); } }