public void UpdateUser(Models.ComboUser user) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; BLL.ComboUser newUser = new ComboUser(); newUser.LoadByPrimaryKey(user.ComboUserID); if (!string.IsNullOrEmpty(user.DisplayName)) newUser.DisplayName = user.DisplayName; if (!string.IsNullOrEmpty(user.Password)) newUser.Password = user.Password; if (!string.IsNullOrEmpty(user.Email)) newUser.Email = user.Email; if (!string.IsNullOrEmpty(user.Bio)) newUser.Bio = user.Bio; if (user.ProfileImgID != 0) newUser.ProfileImgID = user.ProfileImgID; if (user.CoverImgID != 0) newUser.CoverImgID = user.CoverImgID; if (user.GenderID != 0) newUser.GenderID = user.GenderID; if (!string.IsNullOrEmpty(user.SecurityQuestion)) newUser.SecurityQuestion = user.SecurityQuestion; if (!string.IsNullOrEmpty(user.SecurityAnswer)) newUser.SecurityAnswer = user.SecurityAnswer; if (!string.IsNullOrEmpty(user.SecurityWord)) newUser.SecurityWord = user.SecurityWord; if (user.ExternalIDType != 0) { newUser.ExternalIDType = user.ExternalIDType; newUser.ExternalID = user.ExternalID; } if (!string.IsNullOrEmpty(user.DeviceID)) newUser.DeviceID = user.DeviceID; if (user.BirthDate != DateTime.MinValue) newUser.BirthDate = user.BirthDate; if (!string.IsNullOrEmpty(user.Country)) newUser.Country = user.Country; if (!string.IsNullOrEmpty(user.Phone)) newUser.Phone = user.Phone; if (!string.IsNullOrEmpty(user.Website)) newUser.Website = user.Website; if (user.CountryID != 0) newUser.CountryID = user.CountryID; if (!string.IsNullOrEmpty(user.Location)) newUser.Location = user.Location; try { newUser.IsPrivateAccount = user.IsPrivateAccount; } catch (Exception ex) { } newUser.Save(); user.ComboUserID = newUser.ComboUserID; user.UserRankID = newUser.UserRankID; _response.Entity = new Models.ComboUser[]{ user}; SetContentResult(_response); return; }
public void ToggleLikeFriend(int userId, int LikerId) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; bool like = false; ProfileLiker Liker = new ProfileLiker(); if (!Liker.LoadByPrimaryKey(userId, LikerId)) { Liker.AddNew(); Liker.ComboLikerID = LikerId; Liker.ComboUserID = userId; Liker.Save(); like = true; } else { Liker.MarkAsDeleted(); Liker.Save(); } /**************************/ // save notification and push it to device ComboUser creator = new ComboUser(); ComboUser P_Liker = new ComboUser(); creator.LoadByPrimaryKey(userId); P_Liker.LoadByPrimaryKey(LikerId); ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = creator.ComboUserID; if (like) notification.NotificationType = (int)Combo.Models.NotificationType.LIKE_PROFILE; // Like friend else notification.NotificationType = (int)Combo.Models.NotificationType.UNLIKE_PROFILE; // unLike friend notification.NotificationDate = DateTime.UtcNow; notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject("[{'ComboUserID':" + creator.ComboUserID + ",'ComboFriendID':" + P_Liker.ComboUserID + ",'ComboUsername:'******'" + ",'ComboDisplayName:'" + P_Liker.DisplayName + "', 'IsFollowUser' : " + like + "}]"); notification.IsRead = false; notification.Save(); List<Models.ComboNotification> notificationJson = notification.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboNotification { ComboNotificationID = Convert.ToInt32(row["ComboNotificationID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), IsRead = Convert.ToBoolean(row["IsRead"]), NotificationBody = row["NotificationBody"].ToString(), NotificationDate = Convert.ToDateTime(row["NotificationDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, NotificationType = Convert.ToInt32(row["NotificationType"]) }; }).ToList(); SendGCMNotification(Newtonsoft.Json.JsonConvert.SerializeObject(notificationJson), creator.DeviceID); /**************************/ _response.Entity = null; SetContentResult(_response); }
public void ToggleLikePostByID(int id,int userid) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboPostAttachment att = new ComboPostAttachment(); att.GetPostAttachmentsByPostID(id); ComboPostLike likes = new ComboPostLike(); if (!likes.LoadByPrimaryKey(userid, id)) { likes.AddNew(); likes.ComboPostID = id; likes.ComboUserID = userid; likes.Save(); // save notification and push it to device ComboPost post = new ComboPost(); post.LoadByPrimaryKey(id); ComboUser creator = new ComboUser(); ComboUser liker = new ComboUser(); creator.LoadByPrimaryKey(post.ComboUserID); liker.GetUserByUserId(userid); if (creator.ComboUserID != liker.ComboUserID) { List<Models.ComboPostLike> alike = likes.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboPostLike { ComboPostID = Convert.ToInt32(row["ComboPostID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), UserName = liker.UserName, DisplayName = liker.DisplayName, PostText = post.PostText, ProfilePic = liker.GetColumn("ProfilePic").ToString(), Attachments = att.DefaultView.Table.AsEnumerable().Select(r => { return new Models.Attachment { AttachmentID = Convert.ToInt32(r["AttachmentID"]), Path = r["Path"].ToString(), AttachmentTypeID = Convert.ToInt32(r["AttachmentTypeID"]), ThumbsPath = r["ThumbsPath"].ToString() }; }).ToList(), }; }).ToList(); ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = post.ComboUserID; notification.NotificationType = (int)Combo.Models.NotificationType.LIKE; // like notification.NotificationDate = DateTime.UtcNow; notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(alike); notification.IsRead = false; notification.Save(); NotificationUserSettings settings = new NotificationUserSettings(); settings.LoadByPrimaryKey(creator.ComboUserID, (int)Combo.Models.NotificationType.LIKE); bool notify = false; if (settings.RowCount == 0) notify = true; else notify = settings.CanGetNotification(creator.ComboUserID, liker.ComboUserID, (int)Combo.Models.NotificationType.LIKE); if (notify) { List<Models.ComboNotification> notificationJson = notification.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboNotification { ComboNotificationID = Convert.ToInt32(row["ComboNotificationID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), IsRead = Convert.ToBoolean(row["IsRead"]), NotificationBody = row["NotificationBody"].ToString(), NotificationDate = Convert.ToDateTime(row["NotificationDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, NotificationType = Convert.ToInt32(row["NotificationType"]) }; } ).ToList(); string notification_response = SendGCMNotification(Newtonsoft.Json.JsonConvert.SerializeObject(notificationJson), creator.DeviceID); } } } else { likes.MarkAsDeleted(); likes.Save(); } likes.GetPostLikesByPostID(id); List<Models.ComboPostLike> Alllikes = likes.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboPostLike { ComboPostID = Convert.ToInt32(row["ComboPostID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), UserName = row["UserName"].ToString(), DisplayName = row["DisplayName"].ToString(), }; }).ToList(); _response.Entity = Alllikes; SetContentResult(_response); }
public void AddMessageComment(Models.ComboComment comment) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; BLL.ComboComment newComment = new ComboComment(); newComment.AddNew(); if (comment.ComboUserID != 0) newComment.ComboUserID = comment.ComboUserID; else { _response.ErrorCode = 30; _response.ErrorMsg = "Can't insert commnet. No user id ."; _response.bool_result = false; SetContentResult(_response); return; } if (comment.ComboMsgID != 0) newComment.ComboMsgID = comment.ComboMsgID; else { _response.ErrorCode = 31; _response.ErrorMsg = "Can't insert comment. No Msg id ."; _response.bool_result = false; SetContentResult(_response); return; } newComment.CommentText = comment.CommentText.Replace("\n", " "); ; newComment.CommentDate = DateTime.UtcNow; newComment.IsRead = false; newComment.Save(); /**************************/ // save notification and push it to device ComboMsg post = new ComboMsg(); post.LoadByPrimaryKey(comment.ComboMsgID); ComboUser creator = new ComboUser(); ComboUser commentor = new ComboUser(); creator.LoadByPrimaryKey(post.ComboUserID); commentor.GetUserByUserId(comment.ComboUserID); if (creator.ComboUserID != commentor.ComboUserID) { List<Models.ComboComment> acomment = newComment.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboComment { ComboMsgID = Convert.ToInt32(row["ComboMsgID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), ComboUserName = commentor.UserName, ComboDisplayName = commentor.DisplayName, CommentText = newComment.CommentText, CommentDate = newComment.CommentDate.Subtract(new DateTime(1970, 1, 1)).TotalSeconds, ProfilePic = commentor.GetColumn("ProfilePic").ToString() }; }).ToList(); ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = post.ComboUserID; notification.NotificationType = (int)Combo.Models.NotificationType.COMMENT_ON_MESSAGE; // add comment to post notification.NotificationDate = DateTime.UtcNow; notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(acomment); notification.IsRead = false; notification.Save(); NotificationUserSettings settings = new NotificationUserSettings(); settings.LoadByPrimaryKey(creator.ComboUserID, (int)Combo.Models.NotificationType.COMMENT_ON_MESSAGE); bool notify = false; if (settings.RowCount == 0) notify = true; else notify = settings.CanGetNotification(creator.ComboUserID, commentor.ComboUserID, (int)Combo.Models.NotificationType.COMMENT_ON_MESSAGE); if (notify) { List<Models.ComboNotification> notificationJson = notification.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboNotification { ComboNotificationID = Convert.ToInt32(row["ComboNotificationID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), IsRead = Convert.ToBoolean(row["IsRead"]), NotificationBody = row["NotificationBody"].ToString(), NotificationDate = Convert.ToDateTime(row["NotificationDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, NotificationType = Convert.ToInt32(row["NotificationType"]) }; }).ToList(); SendGCMNotification(Newtonsoft.Json.JsonConvert.SerializeObject(notificationJson), creator.DeviceID); } } /**************************/ JavaScriptSerializer js = new JavaScriptSerializer(); Models.Attachment[] att = js.Deserialize<Models.Attachment[]>(js.Serialize(comment.Attachments)); ComboMsgAttachment attachment = new ComboMsgAttachment(); foreach (Models.Attachment item in att) { attachment.AddNew(); attachment.AttachmentID = item.AttachmentID; attachment.ComboMsgID = newComment.ComboMsgID; } attachment.Save(); comment.ComboCommentID = newComment.ComboCommentID; comment.CommentDate = newComment.CommentDate.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; _response.Entity = new Models.ComboComment[] { comment }; SetContentResult(_response); return; }
public void ToggleDeactivateUser(int ID, bool deactivate) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboUser user = new ComboUser(); if (!user.LoadByPrimaryKey(ID)) { _response.ErrorCode = 11; _response.ErrorMsg = "User doesn't exist"; _response.bool_result = false; } else { user.IsDeactivated = deactivate; user.Save(); } _response.Entity = null; SetContentResult(_response); return; }
public void SharePost(int PostId, int UserId) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboPostShare post = new ComboPostShare(); post.AddNew(); post.ComboPostID = PostId; post.ShareDate = DateTime.UtcNow; post.ComboUserID = UserId; post.Save(); /**************************/ // save notification and push it to device ComboPost ref_post = new ComboPost(); ref_post.LoadByPrimaryKey(PostId); ComboPostAttachment att = new ComboPostAttachment(); att.GetPostAttachmentsByPostID(PostId); ComboUser creator = new ComboUser(); ComboUser requester = new ComboUser(); creator.LoadByPrimaryKey(ref_post.ComboUserID); requester.LoadByPrimaryKey(UserId); if (creator.ComboUserID != requester.ComboUserID) { List<Models.ComboSharePost> info = post.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboSharePost { ComboFriendID = requester.ComboUserID, ComboUserID = creator.ComboUserID, ComboUserName = creator.UserName, ComboFriendName = requester.UserName, ComboFriendDisplayName = requester.DisplayName, ComboPostID = Convert.ToInt32(row["ComboPostID"].ToString()), PostText = ref_post.PostText, Attachments = att.DefaultView.Table.AsEnumerable().Select(r => { return new Models.Attachment { AttachmentID = Convert.ToInt32(r["AttachmentID"]), Path = r["Path"].ToString(), AttachmentTypeID = Convert.ToInt32(r["AttachmentTypeID"]), ThumbsPath = r["ThumbsPath"].ToString() }; }).ToList(), }; }).ToList(); ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = creator.ComboUserID; notification.NotificationType = (int)Combo.Models.NotificationType.SHARE_POST; // share post notification.NotificationDate = DateTime.UtcNow; notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(info); notification.IsRead = false; notification.Save(); NotificationUserSettings settings = new NotificationUserSettings(); settings.LoadByPrimaryKey(creator.ComboUserID, (int)Combo.Models.NotificationType.SHARE_POST); bool notify = false; if (settings.RowCount == 0) notify = true; else notify = settings.CanGetNotification(creator.ComboUserID, requester.ComboUserID, (int)Combo.Models.NotificationType.SHARE_POST); if (notify) { List<Models.ComboNotification> notificationJson = notification.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboNotification { ComboNotificationID = Convert.ToInt32(row["ComboNotificationID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), IsRead = Convert.ToBoolean(row["IsRead"]), NotificationBody = row["NotificationBody"].ToString(), NotificationDate = Convert.ToDateTime(row["NotificationDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, NotificationType = Convert.ToInt32(row["NotificationType"]) }; }).ToList(); SendGCMNotification(Newtonsoft.Json.JsonConvert.SerializeObject(notificationJson), creator.DeviceID); } } /**************************/ _response.Entity = null; SetContentResult(_response); }
public void RespondToFriendRequest(int userId, int FriendId, bool isAccepted) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboUserFriend friend = new ComboUserFriend(); if (friend.LoadByPrimaryKey(userId, FriendId)) { if (isAccepted) { friend.RequestApproved = true; } else { friend.MarkAsDeleted(); } friend.Save(); if (isAccepted) { /**************************/ // save notification and push it to device ComboUser creator = new ComboUser(); ComboUser requester = new ComboUser(); creator.LoadByPrimaryKey(userId); requester.LoadByPrimaryKey(FriendId); List<Models.ComboFriendRequest> arequest = friend.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboFriendRequest { ComboFriendID = Convert.ToInt32(row["ComboFriendID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), ComboUserName = creator.UserName, ComboFriendName = requester.UserName, ComboFriendDisplayName = requester.DisplayName }; }).ToList(); ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = requester.ComboUserID; notification.NotificationType = (int)Combo.Models.NotificationType.ACCEPT_FRIEND; // accept friend request notification.NotificationDate = DateTime.UtcNow; notification.NotificationBody = Newtonsoft.Json.JsonConvert.SerializeObject(arequest); notification.IsRead = false; notification.Save(); List<Models.ComboNotification> notificationJson = notification.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboNotification { ComboNotificationID = Convert.ToInt32(row["ComboNotificationID"]), ComboUserID = Convert.ToInt32(row["ComboUserID"]), IsRead = Convert.ToBoolean(row["IsRead"]), NotificationBody = row["NotificationBody"].ToString(), NotificationDate = Convert.ToDateTime(row["NotificationDate"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, NotificationType = Convert.ToInt32(row["NotificationType"]) }; }).ToList(); SendGCMNotification(Newtonsoft.Json.JsonConvert.SerializeObject(notificationJson), requester.DeviceID); /**************************/ } } _response.Entity = null; SetContentResult(_response); }
public void ProcessRequest(HttpContext context) { bool isImage = false, isCover = false, isProfile = false; if (context.Request.Form["IsCover"] != null) isCover = Convert.ToBoolean(context.Request.Form["IsCover"].ToString()); if (context.Request.Form["IsProfile"] != null) isProfile = Convert.ToBoolean(context.Request.Form["IsProfile"].ToString()); int userid = Convert.ToInt32(context.Request.Form["UserId"].ToString()); int typeid = Convert.ToInt32(context.Request.Form["Type"].ToString()); // 1 - image , 2- audio , 3 - video isImage = (typeid == 1); var ext = System.IO.Path.GetExtension(context.Request.Files[0].FileName); string fileName = Guid.NewGuid().ToString(); DirectoryInfo dir = new DirectoryInfo(context.Server.MapPath("~/userfiles/" + userid.ToString())); if (!dir.Exists) dir.Create(); string location = context.Server.MapPath("~/userfiles/"+ userid.ToString() + "/") + fileName + ext; string thumblocation = context.Server.MapPath("~/userfiles/" + userid.ToString() + "/thumb_") + fileName + ".jpg"; context.Request.Files[0].SaveAs(location); BLL.Attachment newfile = new BLL.Attachment(); newfile.AddNew(); if (typeid == 3) { (new NReco.VideoConverter.FFMpegConverter()).GetVideoThumbnail(location, thumblocation); newfile.ThumbsPath = "/userfiles/" + userid.ToString() + "/thumb_" + fileName + ".jpg"; } if (typeid == 2) { try { //string wavfile = location.Replace(".amr", ".wav"); string newlocation = context.Server.MapPath("~/userfiles/" + userid.ToString() + "/") + fileName + ".mp3"; (new NReco.VideoConverter.FFMpegConverter()).ConvertMedia(location, newlocation, "mp3"); ext = ".mp3"; } catch (Exception e) { } } newfile.Path = "/userfiles/"+ userid.ToString() + "/" + fileName + ext; newfile.AttachmentTypeID = typeid; newfile.Save(); if (isCover || isProfile) { BLL.ComboUser user = new ComboUser(); user.LoadByPrimaryKey(userid); if (isCover) user.CoverImgID = newfile.AttachmentID; if (isProfile) user.ProfileImgID = newfile.AttachmentID; user.Save(); } Models.Attachment responseText = new Models.Attachment(); responseText.AttachmentID = newfile.AttachmentID; responseText.Path = newfile.Path; if (newfile.AttachmentTypeID == 3) responseText.ThumbsPath = newfile.ThumbsPath; responseText.AttachmentTypeID = newfile.AttachmentTypeID; Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; _response.Entity = new Models.Attachment[] { responseText }; SetContentResult(_response); }
/// <summary> /// Delete Combo User from db /// </summary> /// <param name="ID">Combo User ID</param> /// <returns>ComboResponse object with Delete Result</returns> public HttpResponseMessage DeleteUser(int ID) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboUser user = new ComboUser(); if (!user.LoadByPrimaryKey(ID)) { _response.ErrorCode = 11; _response.ErrorMsg = "User doesn't exist"; _response.bool_result = false; } else { user.MarkAsDeleted(); user.Save(); } _response.Entity = null; var response = Request.CreateResponse<Models.ComboResponse>(_response); return response; }
public HttpResponseMessage GetUser([FromBody]int ID) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboUser user = new ComboUser(); if (!user.LoadByPrimaryKey(ID)) { _response.ErrorCode = 11; _response.ErrorMsg = "User doesn't exist"; _response.bool_result = false; } else { List<Models.ComboUser> Users = user.DefaultView.Table.AsEnumerable().Select(row => { return new Models.ComboUser { ComboUserID = Convert.ToInt32(row["ComboUserID"]), UserName = row["UserName"].ToString(), DisplayName = row["DisplayName"].ToString(), Password = row["Password"].ToString(), Email = row["Email"].ToString(), Bio = row["Bio"].ToString(), ProfileImgID = row.IsNull("ProfileImgID") ? 0 : Convert.ToInt32(row["ProfileImgID"]), CoverImgID = row.IsNull("CoverImgID") ? 0 : Convert.ToInt32(row["CoverImgID"]), GenderID = row.IsNull("GenderID") ? 0 : Convert.ToInt32(row["GenderID"]), IsActivated = row.IsNull("IsActivated") ? false : Convert.ToBoolean(row["IsActivated"]), ExternalIDType = row.IsNull("ExternalIDType") ? 0 : Convert.ToInt32(row["ExternalIDType"]), ExternalID = row["ExternalID"].ToString(), DeviceID = row["DeviceID"].ToString(), ActivationCode = row.IsNull("ActivationCode") ? Guid.Empty : new Guid(row["ActivationCode"].ToString()), PassResetCode = row.IsNull("PassResetCode") ? Guid.Empty : new Guid(row["PassResetCode"].ToString()) }; }).ToList(); _response.Entity = Users; } var response = Request.CreateResponse<Models.ComboResponse>(_response); return response; }