public IHttpActionResult GetUserNotifications(NumberOfRecord <UserIdAndUserType> model) { StringBuilder traceLog = null; ServiceResponse <Total <List <UserNotificationsVM> > > objResponse = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: GetUserFollowers() Request Data:-UserId-" + model.Param.UserId + ",UserType-" + model.Param.UserType + ",StartIndex-" + model.StartIndex + ",EndIndex-" + model.EndIndex); objResponse = new ServiceResponse <Total <List <UserNotificationsVM> > >(); objResponse.jsonData = NotificationApiBL.GetUserNotificationList(model.StartIndex, model.EndIndex); objResponse.IsResultTrue = true; return(Ok(objResponse)); } catch (Exception ex) { LogManager.LogManagerInstance.WriteErrorLog(ex); return(BadRequest(ex.Message)); } finally { traceLog.AppendLine("End:GetUserFollowers Response Result Status-" + objResponse.IsResultTrue + ",Fetched DateTime-" + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); traceLog = null; } }
public IHttpActionResult UserNotificationSetting(UserNotificationSettingVM model) { StringBuilder traceLog = null; ServiceResponse <bool> objResponse = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: UserNotificationSetting() Request Data:-DeviceToken-" + model.DeviceID + ",DeviceType-" + model.DeviceType + ",IsNotify-" + model.IsNotify + ",NotificationType-" + model.NotificationType); objResponse = new ServiceResponse <bool>(); objResponse.jsonData = NotificationApiBL.SaveUpdateNotification(model); objResponse.IsResultTrue = true; return(Ok(objResponse)); } catch (Exception ex) { LogManager.LogManagerInstance.WriteErrorLog(ex); return(BadRequest(ex.Message)); } finally { traceLog.AppendLine("End:UserNotificationSetting() Response Result Status-" + objResponse.IsResultTrue + ",Fetched DateTime-" + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); traceLog = null; } }
/// <summary> /// Select UserPersonalTrainer /// </summary> /// <param name="usertrainerdetails"></param> /// <returns></returns> public static bool SelectUserPersonalTrainer(UserPersonalTrainerVM usertrainerdetails) { StringBuilder traceLog = new StringBuilder(); using (LinksMediaContext dataContext = new LinksMediaContext()) { try { traceLog.AppendLine("Start: SelectUserPersonalTrainer---- " + DateTime.Now.ToLongDateString()); if (usertrainerdetails.TrainerCredID > 0) { Credentials cred = CommonWebApiBL.GetUserId(Thread.CurrentPrincipal.Identity.Name); if (cred.UserType.Equals(Message.UserTypeUser, StringComparison.OrdinalIgnoreCase)) { tblUser user = dataContext.User.FirstOrDefault(usr => usr.UserId == cred.UserId); if (user != null) { user.PersonalTrainerCredId = usertrainerdetails.TrainerCredID; dataContext.SaveChanges(); if (usertrainerdetails.TrainerCredID > 0) { string selectedUserName = string.Empty; selectedUserName = user.FirstName + " " + user.LastName; NotificationApiBL.SendSelectPrimaryTrainerNotificationToTrainer(usertrainerdetails.TrainerCredID, selectedUserName, cred.UserId, cred.UserType); } return(true); } } } return(false); } catch { throw; } finally { traceLog.AppendLine("End GetTrainerLibraryChallengeList : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Function to post boom on challenge completed(Comment Section) /// </summary> /// <returns>int</returns> /// <devdoc> /// Developer Name - Arvind Kumar /// Date - 05/06/2015 /// </devdoc> public static int PostBoom(ViewPostVM model) { StringBuilder traceLog = null; using (LinksMediaContext _dbContext = new LinksMediaContext()) { try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: ChallengeMessageFeedBL PostBoom"); Credentials objCred = CommonWebApiBL.GetUserId(Thread.CurrentPrincipal.Identity.Name); if (!_dbContext.Booms.Any(b => b.MessageStraemId == model.PostId && b.BoomedBy == objCred.Id)) { tblBoom objBoom = new tblBoom(); objBoom.BoomedBy = objCred.Id; objBoom.BoomedDate = DateTime.Now; objBoom.MessageStraemId = model.PostId; _dbContext.Booms.Add(objBoom); _dbContext.SaveChanges(); // Send the User Notification to user on result boomed if (model.UserId > 0 && !string.IsNullOrEmpty(model.UserType) && !(objCred.UserType == model.UserType && objCred.UserId == model.UserId)) { NotificationApiBL.SendNotificationToALLNType(model.UserId, model.UserType, NotificationType.NewsFeedBoomed.ToString(), objCred, model.PostId); } } return(_dbContext.Booms.Count(b => b.MessageStraemId == model.PostId)); } catch { throw; } finally { traceLog.AppendLine("End : ChallengeMessageFeedBL PostBoom : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Function to authenticate User base on user credetials and get authencation token /// </summary> /// <param name="username">username</param> /// <param name="password">password</param> /// <returns>True/False</returns> public static bool ValidateUser(Credentials usercred, ref Credentials credential, ref string token, ref string userType, ref int userId) { bool success = false; StringBuilder traceLog = null; EncryptDecrypt objEncrypt = null; using (LinksMediaContext _dbContext = new LinksMediaContext()) { tblUserToken objTokenInfo = null; tblCredentials item = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: Login, ValidateUser Method with Param UserName: "******"Start to create user token"); success = true; credential.UserId = item.UserId; credential.UserType = item.UserType; //Code for Last Login of User item.LastLogin = DateTime.Now; /*delete old user token on same devices except current user*/ if (usercred != null && string.IsNullOrEmpty(usercred.DeviceID)) { DeleteOtherUserTokensOnDevices(usercred.DeviceID, usercred.DeviceType); } objTokenInfo = new tblUserToken(); objTokenInfo.UserId = item.Id; objTokenInfo.Token = CommonUtility.GetToken(); objTokenInfo.ClientIPAddress = ConstantKey.DeviceID; objTokenInfo.TokenDevicesID = string.IsNullOrEmpty(usercred.DeviceID) ? string.Empty : usercred.DeviceID; objTokenInfo.DeviceType = string.IsNullOrEmpty(usercred.DeviceType) ? string.Empty : usercred.DeviceType; objTokenInfo.IsExpired = false; objTokenInfo.ExpiredOn = DateTime.Now.AddMinutes(Convert.ToDouble(ConfigurationManager.AppSettings["ExpireDuration"])); objTokenInfo.IsRememberMe = usercred.RememberMe; objTokenInfo.DeviceUID = usercred.DeviceUID; _dbContext.UserToken.Add(objTokenInfo); _dbContext.SaveChanges(); if (string.IsNullOrEmpty(usercred.DeviceID)) { NotificationApiBL.ResetUserNotification(item.Id); } token = objTokenInfo.Token; userType = item.UserType; userId = item.UserId; traceLog.AppendLine("Token are created" + token); } return(success); } finally { objEncrypt.Dispose(); traceLog.AppendLine("Login Start end() : --- " + DateTime.Now.ToLongDateString() + success.ToString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); item = null; traceLog = null; objTokenInfo = null; } } }
/// <summary> /// Function to post comment on challenge completed(Comment Section) /// </summary> /// <returns>CommentVM</returns> /// <devdoc> /// Developer Name - Arvind Kumar /// Date - 05/06/2015 /// </devdoc> public static CommentVM PostComment(CommentVM model) { StringBuilder traceLog = null; using (LinksMediaContext _dbContext = new LinksMediaContext()) { try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: ChallengeMessageFeedBL PostComment"); Credentials cred = CommonWebApiBL.GetUserId(Thread.CurrentPrincipal.Identity.Name); tblComment objComment = new tblComment(); objComment.CommentedBy = cred.Id; objComment.CommentedDate = DateTime.Now; objComment.Message = model.Message; objComment.MessageStraemId = model.PostId; _dbContext.Comments.Add(objComment); _dbContext.SaveChanges(); // User Notification when user post message on other user or trainer post data their team member if (!string.IsNullOrEmpty(model.UserType) && model.UserId == cred.UserId && cred.UserType == model.UserType) { NotificationApiBL.SendALLSenderNotificationByUser(model.PostId, NotificationType.NewsFeedCommented.ToString(), NotificationType.PostCommentedReplyMsg.ToString(), cred); } else if (model.UserId > 0 && !string.IsNullOrEmpty(model.UserType)) { NotificationApiBL.SendNotificationToALLNType(model.UserId, model.UserType, NotificationType.NewsFeedCommented.ToString(), cred, model.PostId); NotificationApiBL.SendALLSenderNotificationByUser(model.PostId, NotificationType.NewsFeedCommented.ToString(), NotificationType.PostCommentedReplyMsg.ToString(), cred); } CommentVM objCommentVM = new CommentVM() { CommentId = objComment.CommentId, PostId = model.PostId, CommentBy = objComment.CommentedBy, Message = model.Message, CommentDate = CommonWebApiBL.GetDateTimeFormat(objComment.CommentedDate), PostedCommentDate = objComment.CommentedDate.ToUniversalTime() }; if (cred.UserType.Equals(Message.UserTypeUser, StringComparison.OrdinalIgnoreCase)) { var user = _dbContext.User.FirstOrDefault(u => u.UserId == cred.UserId); if (user != null) { objCommentVM.ImageUrl = string.IsNullOrEmpty(user.UserImageUrl) ? string.Empty : CommonUtility.VirtualPath + Message.ProfilePicDirectory + user.UserImageUrl; objCommentVM.UserName = user.FirstName + " " + user.LastName; objCommentVM.UserId = user.UserId; objCommentVM.UserType = Message.UserTypeUser; } } else if (cred.UserType.Equals(Message.UserTypeTrainer, StringComparison.OrdinalIgnoreCase)) { var trainer = _dbContext.Trainer.FirstOrDefault(t => t.TrainerId == cred.UserId); if (trainer != null) { objCommentVM.ImageUrl = string.IsNullOrEmpty(trainer.TrainerImageUrl) ? string.Empty : CommonUtility.VirtualPath + Message.ProfilePicDirectory + trainer.TrainerImageUrl; objCommentVM.UserName = trainer.FirstName + " " + trainer.LastName; objCommentVM.UserId = trainer.TrainerId; objCommentVM.UserType = Message.UserTypeTrainer; } } return(objCommentVM); } catch { throw; } finally { traceLog.AppendLine("End : ChallengeMessageFeedBL PostComment : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Function to post Share message text on challenge completed(Comment Section) /// </summary> /// <returns>ViewPostVM</returns> /// <devdoc> /// Developer Name - Arvind Kumar /// Date - 05/06/2015 /// </devdoc> public static ViewPostVM PostShare(PostVM <TextMessageStream> message) { StringBuilder traceLog = null; using (LinksMediaContext _dbContext = new LinksMediaContext()) { try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: ChallengeMessageFeedBL PostShare"); Credentials objCred = CommonWebApiBL.GetUserId(Thread.CurrentPrincipal.Identity.Name); tblMessageStream objMessageStream = new tblMessageStream(); objMessageStream.Content = message.Stream.TextMessage; objMessageStream.MessageType = Message.TextMessageType; objMessageStream.PostedDate = DateTime.Now; objMessageStream.TargetType = Message.ChallengeTargetType; objMessageStream.SubjectId = objCred.Id; objMessageStream.TargetId = message.TargetId; //ChallengeId is assigned. objMessageStream.IsTextImageVideo = true; objMessageStream.IsImageVideo = message.IsImageVideo; _dbContext.MessageStraems.Add(objMessageStream); _dbContext.SaveChanges(); if (objCred.UserType.Equals(Message.UserTypeTrainer, StringComparison.OrdinalIgnoreCase)) { // User Notification when user post message on other user or trainer post data their team member NotificationApiBL.SendALLTeamNotificationByTrainer(objCred.UserId, objMessageStream.MessageStraemId, objCred.UserId, objCred.UserType); } ViewPostVM objViewPostVM = new ViewPostVM() { PostId = objMessageStream.MessageStraemId, Message = objMessageStream.Content, PostedDate = CommonWebApiBL.GetDateTimeFormat(objMessageStream.PostedDate), BoomsCount = _dbContext.Booms.Count(b => b.MessageStraemId == objMessageStream.MessageStraemId), CommentsCount = _dbContext.Comments.Count(cmnt => cmnt.MessageStraemId == objMessageStream.MessageStraemId) }; if (objCred.UserType.Equals(Message.UserTypeUser, StringComparison.OrdinalIgnoreCase)) { var user = (from usr in _dbContext.User join crd in _dbContext.Credentials on usr.UserId equals crd.UserId where crd.UserType == Message.UserTypeUser && crd.Id == objMessageStream.SubjectId select new { usr.FirstName, usr.LastName, usr.UserImageUrl, crd.UserId, crd.UserType }).FirstOrDefault(); if (user != null) { objViewPostVM.PostedByImageUrl = string.IsNullOrEmpty(user.UserImageUrl) ? string.Empty : CommonUtility.VirtualPath + Message.ProfilePicDirectory + user.UserImageUrl; objViewPostVM.UserName = user.FirstName + " " + user.LastName; objViewPostVM.UserId = user.UserId; objViewPostVM.UserType = user.UserType; } } else if (objCred.UserType.Equals(Message.UserTypeTrainer, StringComparison.OrdinalIgnoreCase)) { var trainer = (from t in _dbContext.Trainer join crd in _dbContext.Credentials on t.TrainerId equals crd.UserId where crd.UserType == Message.UserTypeTrainer && crd.Id == objMessageStream.SubjectId select new { t.FirstName, t.LastName, t.TrainerImageUrl, crd.UserId, crd.UserType }).FirstOrDefault(); if (trainer != null) { objViewPostVM.PostedByImageUrl = string.IsNullOrEmpty(trainer.TrainerImageUrl) ? string.Empty : CommonUtility.VirtualPath + Message.ProfilePicDirectory + trainer.TrainerImageUrl; objViewPostVM.UserName = trainer.FirstName + " " + trainer.LastName; objViewPostVM.UserId = trainer.UserId; objViewPostVM.UserType = trainer.UserType; } } return(objViewPostVM); } catch { throw; } finally { traceLog.AppendLine("End:ChallengeMessageFeedBL PostShare --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// validate devices user notification setting and send the notification to iOS and andriod app /// </summary> /// <param name="userId"></param> /// <param name="deviceToken"></param> /// <param name="notificationType"></param> /// <returns></returns> public static bool ValidateAndSendNotification(int userId, string deviceToken, string notificationType, string fullName, string deviceType, int totalpendingNotification, byte[] certificate, int totalbudget, string teamName, int teamjoinUserID = 0, int targetID = 0) { bool success = false; StringBuilder traceLog = new StringBuilder(); string notificationMessage = string.Empty; NotificationType objNotificationType; PushNotificationiOSAndriod objPushNotificationiOSAndriod = null; try { traceLog.AppendLine("Start:ValidateNotificationExits() method"); if (!Enum.TryParse(notificationType, out objNotificationType)) { objNotificationType = NotificationType.None; } int totalNt = 0; switch (objNotificationType) { case NotificationType.TrainerJoinTeam: notificationMessage = string.Format(Message.JoinTeamNotificationMsg, fullName, teamName); break; case NotificationType.TrainerChallege: notificationMessage = string.Format(Message.TrainerNotificationMsg, fullName); break; case NotificationType.FriendChallege: notificationMessage = string.Format(Message.FriendNotificationMsg, fullName); break; case NotificationType.UserSentToReceiver: notificationMessage = string.Format(Message.UserSentToReceiverMsg, fullName); break; case NotificationType.NewsFeedBoomed: { totalNt = NotificationApiBL.GetALLlNotificationListByResultID(targetID, notificationType, userId); --totalNt; if (totalNt > 0) { notificationMessage = totalNt > 1 ? string.Format(Message.MoreNewsFeedBoomedMsg, fullName, totalNt, Message.NtPeople) : string.Format(Message.MoreNewsFeedBoomedMsg, fullName, totalNt, Message.NtPerson); } else { notificationMessage = string.Format(Message.NewsFeedBoomedMsg, fullName); } break; } case NotificationType.NewsFeedCommented: { totalNt = NotificationApiBL.GetALLlNotificationListByResultID(targetID, notificationType, userId); --totalNt; if (totalNt > 0) { notificationMessage = totalNt > 1 ? string.Format(Message.MoreNewsFeedCommentedMsg, fullName, totalNt, Message.NtPeople) : string.Format(Message.MoreNewsFeedCommentedMsg, fullName, totalNt, Message.NtPerson); } else { notificationMessage = string.Format(Message.NewsFeedCommentedMsg, fullName); } } break; case NotificationType.ResultFeedBoomed: { totalNt = NotificationApiBL.GetALLlNotificationListByResultID(targetID, notificationType, userId); --totalNt; if (totalNt > 0) { notificationMessage = totalNt > 1 ? string.Format(Message.MoreResultBoomedMsg, fullName, totalNt, Message.NtPeople) : string.Format(Message.MoreResultBoomedMsg, fullName, totalNt, Message.NtPerson); } else { notificationMessage = string.Format(Message.ResultBoomedMsg, fullName); } break; } case NotificationType.ResultCommented: { totalNt = NotificationApiBL.GetALLlNotificationListByResultID(targetID, notificationType, userId); --totalNt; if (totalNt > 0) { notificationMessage = totalNt > 1 ? string.Format(Message.MoreResultCommentedMsg, fullName, totalNt, Message.NtPeople) : string.Format(Message.MoreResultCommentedMsg, fullName, totalNt, Message.NtPerson); } else { notificationMessage = string.Format(Message.ResultCommentedMsg, fullName); } break; } case NotificationType.TrainerPostToUser: notificationMessage = string.Format(Message.PersonalTrainerPostToUser, fullName); break; case NotificationType.PostCommentedReplyMsg: totalNt = NotificationApiBL.GetALLlNotificationListByResultID(targetID, notificationType, userId); --totalNt; if (totalNt > 0) { notificationMessage = totalNt > 1 ? string.Format(Message.MorePostCommentReplyMsg, fullName, totalNt, Message.NtPeople) : string.Format(Message.MorePostCommentReplyMsg, fullName, totalNt, Message.NtPerson); } else { notificationMessage = string.Format(Message.PostCommentReplyMsg, fullName); } break; case NotificationType.PostResultReplyMsg: totalNt = NotificationApiBL.GetALLlNotificationListByResultID(targetID, notificationType, userId); --totalNt; if (totalNt > 0) { notificationMessage = totalNt > 1 ? string.Format(Message.MoreResultCommentReplyMsg, fullName, totalNt, Message.NtPeople) : string.Format(Message.MoreResultCommentReplyMsg, fullName, totalNt, Message.NtPerson); } else { notificationMessage = string.Format(Message.ResultCommentReplyMsg, fullName); } break; case NotificationType.ProfilesPostToUser: notificationMessage = string.Format(Message.ProfilePostNTMsg, fullName); break; case NotificationType.Following: notificationMessage = string.Format(Message.FollowingNTMsg, fullName); break; case NotificationType.SelectPrimaryTrainer: notificationMessage = string.Format(Message.UserSelectedPrimaryTrainer, fullName); break; } objPushNotificationiOSAndriod = new PushNotificationiOSAndriod(); if (deviceType.Equals(DeviceType.Android.ToString(), StringComparison.OrdinalIgnoreCase)) { success = objPushNotificationiOSAndriod.SendPushNotificationForAndriod(deviceToken, notificationMessage, notificationType, totalpendingNotification, totalbudget, teamjoinUserID); } else { success = objPushNotificationiOSAndriod.SendPushNotificationForiOS(deviceToken, notificationMessage, notificationType, totalpendingNotification, certificate, totalbudget, teamjoinUserID); } return(success); } catch (Exception ex) { LogManager.LogManagerInstance.WriteErrorLog(ex); return(false); } finally { objPushNotificationiOSAndriod = null; traceLog.AppendLine("End ValidateNotificationExits() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } }