public async Task <CommunityTypeViewModel> getCommunityTypeAsync(int id) { var _result = await _unitOfWork.CommunityRepository.GetByID(id); CommunityTypeViewModel model = new CommunityTypeViewModel(); if (_result != null) { model.Id = _result.Id; model.Name = _result.Name; model.Color = _result.Color; model.Description = _result.Description; model.ImageUrl = _result.ImageUrl; model.IsActive = _result.IsActive; model.CommunityUrl = _result.CommunityUrl; model.FooterLinkText = _result.FooterLinkText; model.DisplayIndex = _result.DisplayIndex; } return(model); }
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 <JsonResult> SaveCommunityType(CommunityTypeViewModel model, IFormFile File) { return(Json(await _communitiesService.SaveAsync(model, File))); //return null; }