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 }); } }
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 }); } }
private async Task <BaseModel> Save(CommunityGroupViewModel model, UsersLoginDataModel user, string articeDoclUrl) { try { if (string.IsNullOrEmpty(model.TargetedInterestIds) && model.IsPublicGroup == false) { return(new BaseModel { Status = false, Messsage = "Please select Interest" }); } CommunityGroupsDataModel communityGroupModel = new CommunityGroupsDataModel { CreatedBy = model.UserId, User = user, Title = model.Title, CommunityGroupURL = Urlhelper.GenerateSeoFriendlyURL(model.Title), Description = model.Description, DescriptionVideoUrl = model.DescriptionVideoUrl, IsActive = true, IsPublish = false, IsPublicGroup = model.IsPublicGroup, CommunityId = model.OgranizationsId }; await _unitOfWork.UserCommunityGroupsRepository.Insert(communityGroupModel); //if group is not public then data will save in relation tables if (!model.IsPublicGroup) { //saveing data in relation tables await SaveCommunityTargetedGroupsAsync(model.CommunityTargetedGroupId, user, communityGroupModel); await SaveCommunityTargetedAssociationAsync(model.AssociationId, user, communityGroupModel); //await SaveCommunityTargetedType1Async(model.Type1Id, user, communityGroupModel); //await SaveCommunityTargetedType2Async(model.Type2Id, user, communityGroupModel); await SaveCommunityTargetedInterestsAsync(model.TargetedInterestIds, user, communityGroupModel); } await SaveCommunityGroupsThemeAsync(model.ThemesId, user, communityGroupModel); //SaveOpenHours OpenOfficeHoursViewModel OpenOfficeHoursModel = JsonConvert.DeserializeObject <OpenOfficeHoursViewModel>(model.OpenOfficeHours); OpenOfficeHoursModel.OFromDate = SphixHelper.setDateFromDayName(OpenOfficeHoursModel.OTimeDayName, DateTime.Now.Date); OpenOfficeHoursModel.OToDate = OpenOfficeHoursModel.OFromDate; OpenOfficeHoursModel.IsFirstMeeting = true; await _openOfficeHoursService.SaveOpenHoursAsync(OpenOfficeHoursModel, user, communityGroupModel); //SaveLiveEvent LiveEventViewModel LiveEventModel = JsonConvert.DeserializeObject <LiveEventViewModel>(model.LiveEvent); await SaveLiveEvent(LiveEventModel, user, communityGroupModel); //SaveArticles ArticleViewModel ArticleModel = JsonConvert.DeserializeObject <ArticleViewModel>(model.Article); ArticleModel.ShareDocument = articeDoclUrl; await SaveArticles(ArticleModel, user, communityGroupModel); return(new BaseModel { Status = true, Id = communityGroupModel.Id, Messsage = UMessagesInfo.RecordSaved }); } catch (Exception ex) { return(new BaseModel { Status = false, Messsage = UMessagesInfo.Error }); } }