private void UpdateUserRank(int UserID) { ComboUser user = new ComboUser(); user.GetUserByUserId(UserID); UserActivityLog log = new UserActivityLog(); log.GetActivityDaysByUserID(user.ComboUserID); ComboPost posts = new ComboPost(); posts.GetUserPostsCountByUserID(user.ComboUserID); ComboComment comments = new ComboComment(); comments.GetPostCommentsCountByUserID(user.ComboUserID); ComboPostLike postLikes = new ComboPostLike(); postLikes.GetPostLikesCountByUserID(user.ComboUserID); ProfileFollower followers = new ProfileFollower(); followers.GetProfileFollowersCountByUserID(user.ComboUserID); ProfileFollower followings = new ProfileFollower(); followings.GetProfileFollowingCountByUserID(user.ComboUserID); ProfileLiker profileLikes = new ProfileLiker(); profileLikes.GetProfileLikerCountByUserID(user.ComboUserID); int oldRank = user.UserRankID; if (Convert.ToInt32(log.GetColumn("TotalActivityDays")) > 365 || Convert.ToInt32(posts.GetColumn("TotalPostCount")) > 3000 || Convert.ToInt32(comments.GetColumn("TotalCount")) > 3000 || Convert.ToInt32(postLikes.GetColumn("TotalPostLikes")) > 3000 || Convert.ToInt32(followers.GetColumn("TotalFollowers")) > 3000 || Convert.ToInt32(followings.GetColumn("TotalFollowings")) > 3000 || Convert.ToInt32(profileLikes.GetColumn("TotalProfileLikes")) > 3000) { user.UserRankID = 5; } else if (Convert.ToInt32(log.GetColumn("TotalActivityDays")) > 240 || Convert.ToInt32(posts.GetColumn("TotalPostCount")) > 2000 || Convert.ToInt32(comments.GetColumn("TotalCount")) > 2000 || Convert.ToInt32(postLikes.GetColumn("TotalPostLikes")) > 2000 || Convert.ToInt32(followers.GetColumn("TotalFollowers")) > 2000 || Convert.ToInt32(followings.GetColumn("TotalFollowings")) > 2000 || Convert.ToInt32(profileLikes.GetColumn("TotalProfileLikes")) > 2000) { user.UserRankID = 4; } else if (Convert.ToInt32(log.GetColumn("TotalActivityDays")) > 120 || Convert.ToInt32(posts.GetColumn("TotalPostCount")) > 1000 || Convert.ToInt32(comments.GetColumn("TotalCount")) > 1000 || Convert.ToInt32(postLikes.GetColumn("TotalPostLikes")) > 1000 || Convert.ToInt32(followers.GetColumn("TotalFollowers")) > 1000 || Convert.ToInt32(followings.GetColumn("TotalFollowings")) > 1000 || Convert.ToInt32(profileLikes.GetColumn("TotalProfileLikes")) > 1000) { user.UserRankID = 3; } else if (Convert.ToInt32(log.GetColumn("TotalActivityDays")) > 30 || Convert.ToInt32(posts.GetColumn("TotalPostCount")) > 500 || Convert.ToInt32(comments.GetColumn("TotalCount")) > 500 || Convert.ToInt32(postLikes.GetColumn("TotalPostLikes")) > 500 || Convert.ToInt32(followers.GetColumn("TotalFollowers")) > 500 || Convert.ToInt32(followings.GetColumn("TotalFollowings")) > 500 || Convert.ToInt32(profileLikes.GetColumn("TotalProfileLikes")) > 500) { user.UserRankID = 2; } user.Save(); if (user.UserRankID > oldRank) { /**************************/ // save notification and push it to device UserRank old = new UserRank(); old.LoadByPrimaryKey(oldRank); UserRank newrank = new UserRank(); newrank.LoadByPrimaryKey(user.UserRankID); List<Models.UserRankUpdated> arequest = user.DefaultView.Table.AsEnumerable().Select(row => { return new Models.UserRankUpdated { ComboUserID = Convert.ToInt32(row["ComboUserID"]), UserName = user.UserName, DisplayName = user.DisplayName, OldUserRankID = oldRank, NewUserRankID = user.UserRankID, OldRankName = old.Name, NewRankName = newrank.Name, ProfilePic = row["ProfilePic"].ToString() }; }).ToList(); ComboNotification notification = new ComboNotification(); notification.AddNew(); notification.ComboUserID = user.ComboUserID; notification.NotificationType = (int)Combo.Models.NotificationType.UPDATE_USER_RANK; // update rank 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), user.DeviceID); /**************************/ } }
protected void uiButtonSave_Click(object sender, EventArgs e) { ComboUser user = new ComboUser(); user.GetUserByPasscode(Passcode); user.Password = uiTextBoxPass.Text; user.Save(); uiPanelsuccess.Visible = true; uiPanelError.Visible = false; uiPanelReset.Visible = false; }
/// <summary> /// Add Combo user to db /// </summary> /// <param name="user">Combo user object to be added</param> /// <returns>ComboResponse object with Added User object</returns> public HttpResponseMessage AddUser(Models.ComboUser user) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; BLL.ComboUser newUser = new ComboUser(); BLL.ComboUser _user = new ComboUser(); if (_user.GetUserByUserName(user.UserName)) { _response.ErrorCode = 12; _response.ErrorMsg = "Username exists before"; _response.bool_result = false; var res = Request.CreateResponse<Models.ComboResponse>(_response); return res; } newUser.AddNew(); newUser.UserName = user.UserName; if (!string.IsNullOrEmpty(user.DisplayName)) newUser.DisplayName = user.DisplayName; newUser.Password = user.Password; 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; newUser.IsActivated = user.IsActivated; if (user.ExternalIDType != 0) { newUser.ExternalIDType = user.ExternalIDType; newUser.ExternalID = user.ExternalID; } if (!string.IsNullOrEmpty(user.DeviceID)) newUser.DeviceID = user.DeviceID; newUser.Save(); user.ComboUserID = newUser.ComboUserID; _response.Entity = user; var response = Request.CreateResponse<Models.ComboResponse>(_response); return response; }
public void AddUser(Models.ComboUser user) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; BLL.ComboUser newUser = new ComboUser(); BLL.ComboUser _user = new ComboUser(); if (_user.GetUserByUserName(user.UserName) || _user.GetUserByUserName(user.Email)) { _response.ErrorCode = 12; _response.ErrorMsg = "Username or Email exists before"; _response.bool_result = false; SetContentResult(_response); return; } //if (string.IsNullOrEmpty(user.SecurityQuestion)) //{ // _response.ErrorCode = 14; // _response.ErrorMsg = "No secuity question found"; // _response.bool_result = false; // SetContentResult(_response); // return; //} //if (string.IsNullOrEmpty(user.SecurityAnswer)) //{ // _response.ErrorCode = 15; // _response.ErrorMsg = "No security answer found"; // _response.bool_result = false; // SetContentResult(_response); // return; //} if (string.IsNullOrEmpty(user.SecurityWord)) { _response.ErrorCode = 15; _response.ErrorMsg = "No security word found"; _response.bool_result = false; SetContentResult(_response); return; } newUser.AddNew(); newUser.UserName = user.UserName; if (!string.IsNullOrEmpty(user.DisplayName)) newUser.DisplayName = user.DisplayName; newUser.Password = user.Password; newUser.Email = user.Email; //newUser.SecurityQuestion = user.SecurityQuestion; //newUser.SecurityAnswer = user.SecurityAnswer; newUser.SecurityWord = user.SecurityWord; 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; newUser.IsActivated = user.IsActivated; if (user.ExternalIDType != 0) { newUser.ExternalIDType = user.ExternalIDType; newUser.ExternalID = user.ExternalID; } if (!string.IsNullOrEmpty(user.DeviceID)) newUser.DeviceID = user.DeviceID; // set rank by default newUser.UserRankID = 1; 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; _response.Entity = new Models.ComboUser[]{ user}; try { MailMessage msg = new MailMessage(); string body = Combo.Properties.Resources.registrationBody; string mail = Combo.Properties.Resources.mail; string mailto = user.Email; msg.To.Add(mailto); msg.From = new MailAddress(mail); msg.Subject = Combo.Properties.Resources.registrationSubject; msg.IsBodyHtml = true; msg.BodyEncoding = System.Text.Encoding.UTF8; msg.Body = string.Format(body, user.UserName); SmtpClient client = new SmtpClient(Combo.Properties.Resources.mailserver, Convert.ToInt32(Combo.Properties.Resources.port)); client.UseDefaultCredentials = false; //client.EnableSsl = true; client.Credentials = new System.Net.NetworkCredential(mail, Combo.Properties.Resources.mailpass); client.Send(msg); } catch (Exception ex) { //_response.ErrorCode = 9999; //_response.ErrorMsg = "An Error Occured.Please try again.<br />" + ex.Message; //_response.bool_result = false; } SetContentResult(_response); return; }
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 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 GetUser(string username, string password, string DeviceID) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboUser user = new ComboUser(); if (!user.GetUserByUserNameAndPassword(username, password)) { _response.ErrorCode = 11; _response.ErrorMsg = "User doesn't exist"; _response.bool_result = false; if (user.GetUserByUserName(username)) { _response.ErrorCode = 10; _response.ErrorMsg = "Password not correct"; } } else { // save device id if changed user.DeviceID = DeviceID; user.Save(); // get user info 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()), SecurityQuestion = row["SecurityQuestion"].ToString(), SecurityAnswer = row["SecurityAnswer"].ToString(), UserRankID = Convert.ToInt32(row["UserRankID"]), SecurityWord = row["SecurityWord"].ToString(), Location = row["Location"].ToString() }; }).ToList(); _response.Entity = Users; } SetContentResult(_response); return; }
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 ForgetPassword(string Username) { Models.ComboResponse _response = new Models.ComboResponse(); _response.bool_result = true; _response.ErrorCode = 0; _response.ErrorMsg = ""; ComboUser user = new ComboUser(); if (!user.GetUserByUserName(Username)) { _response.ErrorCode = 11; _response.ErrorMsg = "User doesn't exist"; _response.bool_result = false; } else { user.PassResetCode = Guid.NewGuid(); user.Save(); try { MailMessage msg = new MailMessage(); string body = Combo.Properties.Resources.body; string mail = Combo.Properties.Resources.mail; string mailto = user.Email; msg.To.Add(mailto); msg.From = new MailAddress(mail); msg.Subject = Combo.Properties.Resources.subject; msg.IsBodyHtml = true; msg.BodyEncoding = System.Text.Encoding.UTF8; msg.Body = string.Format(body, user.UserName, user.PassResetCode.ToString()); SmtpClient client = new SmtpClient(Combo.Properties.Resources.mailserver, Convert.ToInt32(Combo.Properties.Resources.port)); client.UseDefaultCredentials = false; client.EnableSsl = true; client.Credentials = new System.Net.NetworkCredential(mail, Combo.Properties.Resources.mailpass); client.Send(msg); } catch (Exception ex) { _response.ErrorCode = 9999; _response.ErrorMsg = "An Error Occured.Please try again.<br />" + ex.Message; _response.bool_result = false; } } _response.Entity = null; var response = Request.CreateResponse<Models.ComboResponse>(_response); return response; }