public IHttpActionResult GetUserCreatedThread(int id) { try { using (var db = new UserDAL()) { Ws_User wsUser = db.GetUserById(id); User_Information userInformation = db.GetUserInformation(id); UserBasicInfoDTO user = new UserBasicInfoDTO(); user.UserName = wsUser.UserName; user.AccountType = wsUser.AccountType; user.IsActive = wsUser.IsActive; user.FullName = userInformation.FullName == null? wsUser.UserName: userInformation.FullName; user.ProfileImage = userInformation.ProfileImage; user.Email = wsUser.Email; return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Data = user })); } } catch (Exception) { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.ERROR })); } }
public Ws_User AddNewUser(Ws_User newUser) { using (var db = new Ws_DataContext()) { db.Ws_User.Add(newUser); db.SaveChanges(); return(GetUserByUserNameOrEmail(newUser.Email)); } }
public Ws_User UpdateUser(Ws_User User) { using (var db = new Ws_DataContext()) { db.Ws_User.AddOrUpdate(User); db.SaveChanges(); return(GetUserByUserNameOrEmail(User.UserName)); } }
protected Ws_User GetCurrentUser() { Ws_User CurrentUser = null; if (User.Identity.Name != null) { using (var db = new UserDAL()) { CurrentUser = db.GetUserByUserNameOrEmail(User.Identity.Name); } } return(CurrentUser); }
/// <summary> /// thuc hien check input /// </summary> /// <param name="userName"></param> /// <param name="emailAdress"></param> /// <returns>true and false</returns> public JsonResult ValidateUser(string userNameOrEmail) { Ws_User validAcc = null; using (var userDal = new UserDAL()) { validAcc = userDal.GetUserByUserNameOrEmail(userNameOrEmail); } if (validAcc != null) { return(Json(true, JsonRequestBehavior.AllowGet)); } else { return(Json(false, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// Get user using user id /// </summary> /// <param name="id"></param> /// <returns></returns> public Ws_User GetUserById(int id) { Ws_User currentUser = new Ws_User(); try { using (var db = new Ws_DataContext()) { currentUser = db.Ws_User.FirstOrDefault(x => x.UserID == id); } } catch (Exception) { //throw; } return(currentUser); }
public Ws_User RegisterFacebook(dynamic me) { string email = me.email; // Create new User var newUser = new Ws_User { Email = email, CreatedDate = DateTime.UtcNow, IsActive = true, UserPassword = string.Empty, IsVerify = true, LastLogin = DateTime.UtcNow, AccountType = false, UserName = "******" + email.Split(new string[] { "@" }, StringSplitOptions.None)[0], VerifyCode = string.Empty, User_Information = new User_Information { UserAddress = me.location, FullName = me.name, EFullName = ConvertToUnSign.Convert(me.name), Gender = me.gender, DoB = (Convert.ToDateTime(me.birthday) != DateTime.MinValue)?Convert.ToDateTime(me.birthday):null, FacebookUrl = me.link, ProfileImage = "https://graph.facebook.com/" + me.id + "/picture?type=large", Country = string.Empty, Phone = string.Empty, OrgnazationIDFollow = string.Empty, UserSignature = string.Empty, Point = 0 } }; // Facebook account // insert user to Database newUser = AddNewUser(newUser); return(newUser); }
/// <summary> /// Get full information of User /// #Note: If you add new field to UserBasicInfoDTO model - /// Please write code to set that information in this function /// </summary> /// <param name="userId"></param> /// <returns>UserBasicInfoDTO</returns> public UserBasicInfoDTO GetFullInforOfUserAsBasicUser(int userId) { UserBasicInfoDTO currentUser = new UserBasicInfoDTO(); int numberEventDonatedIn = 0; decimal totalMoneyDonatedIn = 0; decimal lastDonateMoney = 0; string lastDonateDate = ""; int numberOfPost = 0; try { Ws_User wsUser = GetUserById(userId); User_Information userInformation = GetUserInformation(userId); //Get infomation about donation of this user using (var db = new DonationDAL()) { numberEventDonatedIn = db.GetNumberEventDonatedInByUsingUserId(userId); totalMoneyDonatedIn = db.GetTotalMoneyDonatedInByUsingUserId(userId); Donation lastDonation = db.GetLastDonateInformation(userId); if (lastDonation != null) { lastDonateMoney = lastDonation.DonatedMoney; lastDonateDate = lastDonation.DonatedDate.ToString("H:mm:ss dd/MM/yy"); } } //Get number of post for current user using (var db = new ThreadDAL()) { numberOfPost = db.GetNumberOfPostPerUser(userId); } using (var db = new OrganizationDAL()) { Organization org = db.GetOrganizationById(userId); if (org != null) { currentUser.OrganazationName = org.OrganizationName; } if (currentUser.OrganazationName == "") { currentUser.OrganazationName = "Chưa có"; } } using (var db = new Ws_DataContext()) { currentUser.JoinedDate = db.Ws_User.Where(x => x.UserID == userId).SingleOrDefault().CreatedDate.ToString("dd/mm/yyyy"); } //get ranking information WsRanking ranking = new WsRanking(); RankingDTO rank = new RankingDTO(); //Set information for user which want to get currentUser.UserId = userId; currentUser.UserName = wsUser.UserName; currentUser.AccountType = wsUser.AccountType; currentUser.IsActive = wsUser.IsActive; currentUser.IsVerify = wsUser.IsVerify; currentUser.Email = wsUser.Email; if (userInformation != null) { rank = ranking.RankingWithPoint(userInformation.Point); currentUser.FacebookUri = userInformation.FacebookUrl; currentUser.FullName = userInformation.FullName; currentUser.ProfileImage = userInformation.ProfileImage; currentUser.Gender = userInformation.Gender; currentUser.Phone = userInformation.Phone; currentUser.Address = userInformation.UserAddress; currentUser.UserSignature = userInformation.UserSignature; if (userInformation.DoB != null) { currentUser.DOB = userInformation.DoB.Value.ToString("dd/MM/yyyy"); } currentUser.Country = userInformation.Country; currentUser.FacebookUri = userInformation.FacebookUrl; currentUser.CreateDate = wsUser.CreatedDate.ToString("dd/MM/yyyy"); currentUser.Point = userInformation.Point; } currentUser.NumberOfPost = numberOfPost; if (rank.CurrentRank == 0) { currentUser.CurrentRank = "Mới"; } else if (rank.CurrentRank == 200) { currentUser.CurrentRank = "Đồng"; } else if (rank.CurrentRank == 500) { currentUser.CurrentRank = "Bạc"; } else if (rank.CurrentRank == 2000) { currentUser.CurrentRank = "Vàng"; } else if (rank.CurrentRank == 5000) { currentUser.CurrentRank = "Bạch Kim"; } else if (rank.CurrentRank == 10000) { currentUser.CurrentRank = "Kim Cương"; } currentUser.RankPercent = rank.RankPercent; currentUser.NumberEventDonatedIn = numberEventDonatedIn; currentUser.TotalMoneyDonatedIn = totalMoneyDonatedIn; currentUser.LastDonateMoney = lastDonateMoney; currentUser.LastDonateDate = lastDonateDate; } catch (Exception) { //throw; } return(currentUser); }
public ActionResult Register(UserRegisterDTO account) { try { //Save data to database Random rnd = new Random(); var verifycode = rnd.Next(000001, 999999).ToString(); var Md5pass = MD5Helper.MD5Encrypt(account.PassWord); var newUser = new Ws_User { Email = account.Email, UserName = account.UserName, UserPassword = Md5pass, CreatedDate = DateTime.UtcNow, IsActive = true, IsVerify = false, AccountType = false, VerifyCode = verifycode, User_Information = new User_Information { ProfileImage = "Content/Images/avatar_default.png", FullName = account.FullName, EFullName = ConvertToUnSign.Convert(account.FullName) } }; using (var userDal = new UserDAL()) { userDal.AddNewUser(newUser); } // Send Verify code //khai báo biến để gửi mã xác nhận var fromAddress = new MailAddress(WsConstant.VerifyEmail.AdminEmail, WsConstant.VerifyEmail.WsOrganization); var toAddress = new MailAddress(account.Email, account.UserName); string fromPassword = WsConstant.VerifyEmail.AdminEmailPass; string subject = WsConstant.VerifyEmail.EmailSubject; string body = WsConstant.VerifyEmail.EmailContentFirst + " Tên đăng nhập : " + account.UserName + "\n Mã xác nhận : " + verifycode + WsConstant.VerifyEmail.EmailContentLast; //xu li gui mail var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); } //chuyển đến trang đăng ký thành công return(Redirect("/#/RegisterSuccess")); } catch (Exception ex) { ViewBag.ErrorMessage = ex; return(Redirect("/#/Error")); } }