/// <summary> /// Save and update data in Open Office Hours table /// </summary> /// <param name="model"></param> /// <param name="user">if user model is null then please pass UserId into the OpenOfficeHoursViewModel</param> /// <param name="communityGroupsData">if communityGroupsData model is null then please pass CommunityGroupId into the OpenOfficeHoursViewModel</param> /// <returns></returns> public async Task <BaseModel> SaveOpenHoursAsync(OpenOfficeHoursViewModel model, UsersLoginDataModel user, CommunityGroupsDataModel communityGroupsData) { if (user == null) { user = await _unitOfWork.UserLoginRepository.GetByID(model.UserId); } if (communityGroupsData == null) { communityGroupsData = await _unitOfWork.UserCommunityGroupsRepository.GetByID(model.CommunityGroupId); } if (model.Id == 0) { CommunityOpenOfficeHours dataModel = new CommunityOpenOfficeHours { CreatedBy = user.Id, User = user, CommunityGroups = communityGroupsData, OTitle = model.OTitle, OName = model.OName, ODescription = model.ODescription, OFrequency = model.OFrequency, OFromDate = model.OFromDate, // setDateFromDayName(model.OTimeDayName, model.OFromDate), OToDate = model.OFromDate, // setDateFromDayName(model.OTimeDayName, model.OFromDate), OTime = model.OTime, OTimeDayName = model.OTimeDayName, OTimeZone = model.OTimeZone, MaxAttendees = model.MaxAttendees, WhoCanAttend = model.WhoCanAttend, IsActive = true, IsFirstMeeting = model.IsFirstMeeting, NextMeetingToken = model.NextMeetingToken, LastSessionId = model.LastSessionId, AddHours = model.AddHours }; await _unitOfWork.UserCommunityOpenOfficeHoursRepository.Insert(dataModel); if (model.AddHours) { await _context.LoadStoredProc("AddHoursInOpenOfficeHours") .WithSqlParam("Id", dataModel.Id) .ExecuteStoredProcAsync((handler) => { // do something with your results. }); } return(new BaseModel { Status = true, Id = dataModel.Id, Messsage = UMessagesInfo.RecordSaved }); } else { var openOfficeHoursModel = await _unitOfWork.UserCommunityOpenOfficeHoursRepository.GetByID(model.Id); openOfficeHoursModel.OTitle = model.OTitle; openOfficeHoursModel.OName = model.OName; openOfficeHoursModel.ODescription = model.ODescription; openOfficeHoursModel.OFrequency = model.OFrequency; if (openOfficeHoursModel.OTimeDayName.ToLower().Trim() != model.OTimeDayName.ToLower().Trim()) { openOfficeHoursModel.OFromDate = SphixHelper.setDateFromDayName(model.OTimeDayName, DateTime.Now.Date); openOfficeHoursModel.OToDate = openOfficeHoursModel.OFromDate; } else { openOfficeHoursModel.OFromDate = model.OFromDate;// setDateFromDayName(model.OTimeDayName, model.OFromDate); openOfficeHoursModel.OToDate = openOfficeHoursModel.OFromDate; } openOfficeHoursModel.OTime = model.OTime; openOfficeHoursModel.OTimeDayName = model.OTimeDayName; openOfficeHoursModel.OTimeZone = model.OTimeZone; openOfficeHoursModel.MaxAttendees = model.MaxAttendees; openOfficeHoursModel.WhoCanAttend = model.WhoCanAttend; openOfficeHoursModel.IsActive = true; //openOfficeHoursModel.AddHours = model.AddHours; //openOfficeHoursModel.IsFirstMeeting = model.IsFirstMeeting; await _unitOfWork.UserCommunityOpenOfficeHoursRepository.Update(openOfficeHoursModel); return(new BaseModel { Status = true, Id = model.Id, Messsage = UMessagesInfo.RecordSaved }); } }
public async Task <IActionResult> AddOpenOfficeHours(OpenOfficeHoursViewModel model, long OpenHoursId) { var openHoursModel = await _openOfficeHoursService.getOpenHoursAsync(OpenHoursId); model.UserId = _claimAccessor.UserId; model.MaxAttendees = openHoursModel.MaxAttendees; model.ODescription = openHoursModel.ODescription; model.OFrequency = openHoursModel.OFrequency; TimeSpan difference = DateTime.Now.Date - openHoursModel.OFromDate.Date; if (difference.Days > 7) { model.OFromDate = SphixHelper.setDateFromDayName(openHoursModel.OTimeDayName, DateTime.Now.Date); } else if (difference.Days == 0) { model.OFromDate = openHoursModel.OFromDate; } else { model.OFromDate = SphixHelper.setDateFromDayName(openHoursModel.OTimeDayName, openHoursModel.OFromDate); } model.OToDate = model.OFromDate; model.OName = openHoursModel.OName; model.OTime = openHoursModel.OTime; model.OTitle = openHoursModel.OTitle; model.WhoCanAttend = openHoursModel.WhoCanAttend; model.OTimeDayName = openHoursModel.OTimeDayName; model.IsFirstMeeting = false; string token = Guid.NewGuid().ToString().Replace("-", ""); model.NextMeetingToken = token; model.LastSessionId = 0; var _existingTable = await _openOfficeHoursService.CheckTableIsExist(_claimAccessor.UserId, model.CommunityGroupId, model.OTimeZone, model.OFromDate); if (_existingTable.Status) { return(Json(new BaseModel { Status = false, Messsage = UMessagesInfo.RecordExist })); } var _result = await _openOfficeHoursService.SaveOpenHoursAsync(model, null, null); if (_result.Status) { var pathToFile = _env.WebRootPath + Path.DirectorySeparatorChar.ToString() + "Templates" + Path.DirectorySeparatorChar.ToString() + "EmailTemplates" + Path.DirectorySeparatorChar.ToString() + "OpenHoursMeetingCreateNewTable.html"; string HtmlBody = string.Empty; using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile)) { HtmlBody = SourceReader.ReadToEnd(); } var callbackUrl = Url.Action("ActiveNextSession", "CommunityOpenOfficeHours", null, protocol: HttpContext.Request.Scheme) + "/" + token; await _openHoursMailService.SendMailOnCreateNewTableAsync(_claimAccessor.UserId, token, callbackUrl, HtmlBody, model.OFromDate.ToShortDateString() + " at " + model.OTime + " " + model.OTimeZone); //send thanks mail } return(Json(_result)); }
public async Task <IActionResult> ActiveNextSession(string Id) { OpenOfficeHoursViewModel model = new OpenOfficeHoursViewModel(); if (!string.IsNullOrEmpty(Id)) { var openHoursModel = await _openOfficeHoursService.getOpenHoursAsync(Id); if (openHoursModel != null && openHoursModel.IsMeetingTokenUsed == false) { //DateTime nextMeetingDate = openHoursModel.OFromDate.AddDays(7); model.UserId = openHoursModel.CreatedBy; model.MaxAttendees = openHoursModel.MaxAttendees; model.ODescription = openHoursModel.ODescription; model.OFrequency = openHoursModel.OFrequency; TimeSpan difference = DateTime.Now.Date - openHoursModel.OFromDate.Date; if (difference.Days > 7) { model.OFromDate = SphixHelper.setDateFromDayName(openHoursModel.OTimeDayName, DateTime.Now.Date); } else if (difference.Days == 0) { model.OFromDate = openHoursModel.OFromDate; } else { model.OFromDate = SphixHelper.setDateFromDayName(openHoursModel.OTimeDayName, openHoursModel.OFromDate); } // model.OFromDate = nextMeetingDate; model.OTimeZone = openHoursModel.OTimeZone; model.OTime = openHoursModel.OTime; model.OToDate = model.OFromDate;// openHoursModel.OToDate; model.OName = openHoursModel.OName; model.OTime = openHoursModel.OTime; model.OTitle = openHoursModel.OTitle; model.WhoCanAttend = openHoursModel.WhoCanAttend; model.OTimeDayName = openHoursModel.OTimeDayName; model.CommunityGroupId = openHoursModel.CommunityGroups.Id; string token = Guid.NewGuid().ToString().Replace("-", ""); model.NextMeetingToken = token; model.IsFirstMeeting = false; model.LastSessionId = openHoursModel.Id; var _existingTable = await _openOfficeHoursService.CheckTableIsExist(model.UserId, model.CommunityGroupId, model.OTimeZone, model.OFromDate); if (_existingTable.Status) { return(Json(_existingTable)); } var _result = await _openOfficeHoursService.SaveOpenHoursAsync(model, null, null); if (_result.Status) { await _openOfficeHoursService.UpdateNextMeetingToken(openHoursModel.Id); //IsMeetingTokenUsed var pathToFile = _env.WebRootPath + Path.DirectorySeparatorChar.ToString() + "Templates" + Path.DirectorySeparatorChar.ToString() + "EmailTemplates" + Path.DirectorySeparatorChar.ToString() + "OpenHoursMeetingCreateNewTable.html"; string HtmlBody = string.Empty; using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile)) { HtmlBody = SourceReader.ReadToEnd(); } var callbackUrl = Url.Action("ActiveNextSession", "CommunityOpenOfficeHours", null, protocol: HttpContext.Request.Scheme) + "/" + token; await _openHoursMailService.SendMailOnCreateNewTableAsync(model.UserId, token, callbackUrl, HtmlBody, model.OFromDate.ToShortDateString() + " at " + model.OTime + " " + model.OTimeZone); //send thanks mail } } else { model.IsMeetingTokenUsed = true; } } return(View(model)); }
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 }); } }