private async Task <BaseModel> Update(CommunityGroupViewModel model) { CommunityGroupsDataModel communityGroupModel = await _unitOfWork.UserCommunityGroupsRepository.GetByID(model.Id); try { communityGroupModel.Title = model.Title; communityGroupModel.Description = model.Description; if (!string.IsNullOrEmpty(model.DescriptionVideoUrl)) { await _awsS3Bucket.DeleteFileAsync(communityGroupModel.DescriptionVideoUrl); communityGroupModel.DescriptionVideoUrl = model.DescriptionVideoUrl; } communityGroupModel.CommunityGroupURL = Urlhelper.GenerateSeoFriendlyURL(model.Title); //communityGroupModel.IsActive = true; //communityGroupModel.IsPublish = true; communityGroupModel.IsPublicGroup = model.IsPublicGroup; communityGroupModel.AddedDate = DateTime.Now; communityGroupModel.CommunityId = model.OgranizationsId; await _unitOfWork.UserCommunityGroupsRepository.Update(communityGroupModel); //if group is not public then data will save in relation tables if (!model.IsPublicGroup) { //saving data in relation tables await SaveCommunityTargetedGroupsAsync(model.CommunityTargetedGroupId, communityGroupModel.User, communityGroupModel); await SaveCommunityTargetedAssociationAsync(model.AssociationId, communityGroupModel.User, communityGroupModel); //await SaveCommunityTargetedType1Async(model.Type1Id, communityGroupModel.User, communityGroupModel); //await SaveCommunityTargetedType2Async(model.Type2Id, communityGroupModel.User, communityGroupModel); await SaveCommunityTargetedInterestsAsync(model.TargetedInterestIds, communityGroupModel.User, communityGroupModel); } await SaveCommunityGroupsThemeAsync(model.ThemesId, communityGroupModel.User, communityGroupModel); //SaveOpenHours OpenOfficeHoursViewModel OpenOfficeHoursModel = JsonConvert.DeserializeObject <OpenOfficeHoursViewModel>(model.OpenOfficeHours); //OpenOfficeHoursModel.OFromDate = SphixHelper.setDateFromDayName(OpenOfficeHoursModel.OTimeDayName, DateTime.Now.Date); //OpenOfficeHoursModel.OToDate = OpenOfficeHoursModel.OFromDate; await _openOfficeHoursService.SaveOpenHoursAsync(OpenOfficeHoursModel, communityGroupModel.User, communityGroupModel); return(new BaseModel { Status = true, Id = communityGroupModel.Id, Messsage = UMessagesInfo.RecordSaved }); } catch (Exception ex) { return(new BaseModel { Status = false, Messsage = UMessagesInfo.Error }); } }
private async Task <BaseModel> Update(ArticleViewModel model) { CommunityArticles dataModel = await _unitOfWork.UserCommunityArticlesRepository.GetByID(model.Id); dataModel.Title = model.ArticleTitle; dataModel.Description = model.ArticleDescription; if (!string.IsNullOrEmpty(model.ShareDocument)) { await _awsS3Bucket.DeleteFileAsync(dataModel.ShareDocUrl); dataModel.ShareDocUrl = model.ShareDocument; } dataModel.IsActive = true; dataModel.AddedDate = DateTime.Now; await _unitOfWork.UserCommunityArticlesRepository.Update(dataModel); return(new BaseModel { Status = true, Id = dataModel.Id, Messsage = UMessagesInfo.RecordSaved }); }
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 }); } }