public string Login(User data) { //bool isPasswordCorrect = false; string un = data.Name; string Password = data.Password; using (UserEntities entity = new UserEntities()) { var user = entity.Users.Where(u => u.Name == un).FirstOrDefault(); if (user != null) { if (Password == user.Password) { Session["LoginID"] = user.UserId; Session["Username"] = user.Name + ' ' + user.FullName; return(user.UserId.ToString()); } else { return("0"); } } else { return("-1"); } } }
//編輯會員頁面 public ActionResult Edit(string id) { //抓取輸入id的資料 ManageUser result = new ManageUser(); using (UserEntities db = new UserEntities()) { result = (from s in db.AspNetUsers where s.Id == id select new ManageUser { Id = s.Id, UserName = s.UserName, Email = s.Email }).FirstOrDefault(); } //判斷此id是否有資料 if (result != default(ManageUser)) { return(View(result)); } else //如果沒有資料 { TempData["ResultMessage"] = "資料有誤,請檢查"; return(RedirectToAction("Index")); } }
public User Get(int id) { using (UserEntities entities = new UserEntities()) { return((User)entities.Users.ToList()[entities.Users.ToList().FindIndex(user => user.id == id)]); } }
// POST api/userentities/ public HttpResponseMessage Post(int EntityId, [FromBody] User value) { ServerValidationInfo vi = null; value.CreateDate = DateTime.Now; value.UpdateDate = DateTime.Now; if (!ModelState.IsValid) { vi = new ServerValidationInfo(ModelState); } if (vi != null && vi.ContainsError) { return(Request.CreateResponse(HttpStatusCode.BadRequest, vi)); } var rel = new UserEntities() { EntityId = EntityId, User = value }; context.Entry(rel).State = System.Data.EntityState.Added; context.SaveChanges(); value.UserEntitieses = null; return(Request.CreateResponse(HttpStatusCode.OK, value)); }
public int InsertPhoneCode(PhoneCodeModel model) { using (UserEntities user = new UserEntities()) { try { //新增PhoneCode U_PhoneCode newcode = new U_PhoneCode() { Phone = model.Phone, Code = model.Code.ToString(), StartTime = model.StartTime, EndTime = model.EndTime, ClientIp = model.ClientIp.ToString(), SmsType = model.SmsType.ToString(), SmsContent = model.SmsContent.ToString() }; user.U_PhoneCode.Add(newcode); user.SaveChanges(); } catch (Exception e) { return(0); } } return(1); }
public PhoneCodeModel GetPhoneCode(string Phone, int smstype) { PhoneCodeModel data = new PhoneCodeModel(); using (UserEntities user = new UserEntities()) { try { var getinfo = user.U_PhoneCode.Where(s => s.Phone == Phone && s.EndTime > DateTime.Now && s.SmsType == smstype.ToString()).FirstOrDefault(); if (getinfo == null) { return(null); } if (getinfo != null) { data.Id = getinfo.ID.ToString(); data.Phone = getinfo.Phone; data.Code = getinfo.Code; data.StartTime = Convert.ToDateTime(getinfo.StartTime); data.EndTime = Convert.ToDateTime(getinfo.EndTime); data.ClientIp = getinfo.ClientIp; data.SmsType = getinfo.SmsType; data.SmsContent = getinfo.SmsContent; return(data); } } catch (Exception e) { return(null); } } return(data); }
public ColumnGridDetailsDto GetGridInfo(string TableName) { ColumnGridDetailsDto gridDetailsDto = new ColumnGridDetailsDto(); UserEntities db = new UserEntities(); var checkUserTableExists = db.ColumnUsersSettings.Where(x => x.GridName == TableName).ToList(); if (checkUserTableExists.Count > 0) { gridDetailsDto.visibleColumns = db.ColumnUsersSettings.Where(x => x.GridName == TableName && x.IsVisible == true).AsEnumerable() .Select(x => new ColumnDto { ColumnId = x.Id, ColumnText = x.ColumnText, GridName = x.GridName, ColumnFilterId = x.ColumnFilterId, ColumnType = x.ColumnType, ColumnWidth = x.ColumnWidth, OrderBy = x.ColumnOrder }).OrderBy(x => x.OrderBy).ToList(); gridDetailsDto.hiddenColumns = db.ColumnUsersSettings.Where(x => x.GridName == TableName && x.IsVisible == false).AsEnumerable() .Select(x => new ColumnDto { ColumnId = x.Id, ColumnText = x.ColumnText, GridName = x.GridName, ColumnFilterId = x.ColumnFilterId, ColumnType = x.ColumnType, ColumnWidth = x.ColumnWidth, OrderBy = x.ColumnOrder }).OrderBy(x => x.OrderBy).ToList(); } else { gridDetailsDto.visibleColumns = db.ColumnUsersSettings.Where(x => x.GridName == TableName && x.IsVisible == true).AsEnumerable() .Select(x => new ColumnDto { ColumnId = x.Id, ColumnText = x.ColumnText, GridName = x.GridName, ColumnFilterId = x.ColumnFilterId, ColumnType = x.ColumnType, ColumnWidth = x.ColumnWidth, OrderBy = x.ColumnOrder }).OrderBy(x => x.OrderBy).ToList(); gridDetailsDto.hiddenColumns = db.ColumnUsersSettings.Where(x => x.GridName == TableName && x.IsVisible == false).AsEnumerable() .Select(x => new ColumnDto { ColumnId = x.Id, ColumnText = x.ColumnText, GridName = x.GridName, ColumnFilterId = x.ColumnFilterId, ColumnType = x.ColumnType, ColumnWidth = x.ColumnWidth, OrderBy = x.ColumnOrder }).OrderBy(x => x.OrderBy).ToList(); } return(gridDetailsDto); }
/// <summary> /// 查询设备图表名称是否存在 /// </summary> public ReturnItem <RetHomeConfiguration> CheckDeviceInfoByChartName(HomeConfigurationModel parameter) { ReturnItem <RetHomeConfiguration> r = new ReturnItem <RetHomeConfiguration>(); using (UserEntities user = new UserEntities()) { try { var OrgID = Convert.ToInt32(parameter.OrgID); var checkchart = user.U_HomeConfiguration.Where(s => s.ChartName == parameter.ChartName && s.OrgID == OrgID).FirstOrDefault(); if (checkchart == null) { r.Data = null; r.Code = 1; r.Msg = "未找到设备图表"; return(r); } if (checkchart != null) { r.Msg = "已存在设备图表"; r.Code = 0; } } catch (Exception e) { r.Msg = "内部错误请重试"; log.ErrorFormat("内部错误:{0},{1}", e.Message, e.StackTrace); r.Code = -1; } } return(r); }
public void GameRestart() { UserEntities playerEntity = new UserEntities(); Player player1 = new Player(); var pl = (from player in playerEntity.Players where player.P_State == true select player).SingleOrDefault(); if (pl != null) { if (pl.P_Score < (int)gameBoard.GetScore) { pl.P_Score = (int)gameBoard.GetScore; mainWindowControl.lb_name_score.Text = gameBoard.GetScore.ToString(); playerEntity.SaveChanges(); } } board.GetMainGrid.Clear(); board.GetExtraGrid.Clear(); level = 1; mainWindowControl.btnStartStop.Enabled = true; mainWindowControl.pnGameOver.Visible = false; gameBoard = new GameBoard(board); SetLevel(level); Timer.Start(); }
public ActionResult AddComment(int id, string Content, int rating) { //取得使用者Id var UserId = HttpContext.User.Identity.Name; var currentDateTime = DateTime.Now; using (UserEntities Userdb = new UserEntities()) { var NickName = (from s in Userdb.AspNetUsers where s.UserName == UserId select s.Name).FirstOrDefault(); var ImgUrl = (from s in Userdb.AspNetUsers where s.UserName == UserId select s.ImgUrl).FirstOrDefault(); rating = (rating <= 0) ? 1 :(rating >= 5) ? 5 : rating; var comment = new ProductCommet() { ProductId = id, UserId = NickName, Content = Content, CreateDate = currentDateTime, ImgUrl = ImgUrl, Stars = rating }; using (CartsEntities db = new CartsEntities()) { db.ProductCommets.Add(comment); db.SaveChanges(); } } return(RedirectToAction("Detail", new { id = id })); }
private object GetStub <T>(List <T> items) { object data = null; if (typeof(T).Equals(typeof(Configuration))) { data = new Configurations(items as List <Configuration>); } else if (typeof(T).Equals(typeof(Category))) { data = new Categories(items as List <Category>); } else if (typeof(T).Equals(typeof(String))) { data = new Blacklists(items as List <string>); } else if (typeof(T).Equals(typeof(Query))) { data = new Queries(items as List <Query>); } else if (typeof(T).Equals(typeof(UserEntity))) { data = new UserEntities(items as List <UserEntity>); } else if (typeof(T).Equals(typeof(SentimentPhrase))) { data = new SentimentPhrases(items as List <SentimentPhrase>); } else { throw new ArgumentOutOfRangeException(); } return(data); }
public List <UserEntity> GetEntities(string configId = null) { AuthResponse authResponse = this.Get <UserEntity>(configId); List <UserEntity> obj = new List <UserEntity>(); switch (_format) { case "json": { List <UserEntity> result = this.ProcessGetResponse <List <UserEntity> >(authResponse); if (result != null) { obj = result; } } break; case "xml": { UserEntities result = this.ProcessGetResponse <UserEntities>(authResponse); if (result != null) { obj = result.Data; } } break; default: throw new ArgumentOutOfRangeException(); } return(obj); }
// PUT api/userentities/ public HttpResponseMessage Put([FromBody] UserEntities value, string filter = null) { ServerValidationInfo vi = null; if (!ModelState.IsValid) { vi = new ServerValidationInfo(ModelState); } if (filter == null) { context.Entry(value).State = System.Data.EntityState.Modified; } else { var old = context.UserEntitieses.SingleOrDefault(queryBuider.CreateWhere(filter)); old.UserId = value.UserId; old.EntityId = value.EntityId; } if (vi != null && vi.ContainsError) { return(Request.CreateResponse(HttpStatusCode.BadRequest, vi)); } var result = context.SaveChanges() > 0; return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public ActionResult SearchByUserName(string UserName) { //儲存查出來的UserId string SearchUserId = null; using (UserEntities db = new UserEntities()) { SearchUserId = (from s in db.AspNetUsers where s.UserName == UserName select s.UserName).FirstOrDefault(); } //如果有找到 if (!string.IsNullOrEmpty(SearchUserId)) { using (CartsEntities db = new CartsEntities()) { var result = (from s in db.OrderSet where s.UserId == SearchUserId select s).ToList(); return(View("Index", result)); } } else { return(View("Index", new List <Order>())); } }
public ColumnGridDetailsDto GetDefaultGridInfo(string TableName) { UserEntities db = new UserEntities(); ColumnGridDetailsDto gridColumnsInfo = new ColumnGridDetailsDto(); gridColumnsInfo.visibleColumns = db.ColumnSettings.Where(x => x.GridName == TableName && x.IsVisible == true).Select(x => new ColumnDto { ColumnId = x.Id, ColumnText = x.ColumnText, GridName = x.GridName, ColumnFilterId = x.ColumnFilterId, ColumnType = x.ColumnType, ColumnWidth = x.ColumnWidth, OrderBy = x.ColumnOrder }).OrderBy(x => x.OrderBy).ToList(); gridColumnsInfo.hiddenColumns = db.ColumnSettings.Where(x => x.GridName == TableName && x.IsVisible == false).Select(x => new ColumnDto { ColumnId = x.Id, ColumnText = x.ColumnText, GridName = x.GridName, ColumnFilterId = x.ColumnFilterId, ColumnType = x.ColumnType, ColumnWidth = x.ColumnWidth, OrderBy = x.ColumnOrder }).OrderBy(x => x.OrderBy).ToList(); return(gridColumnsInfo); }
public ActionResult Login(UserLogin aUserlogin) { if (ModelState.IsValid) { using (UserEntities db = new UserEntities()) { var obj = db.Users.Where(a => a.UserName.Equals(aUserlogin.userName) && a.Password.Equals(aUserlogin.Password)) .FirstOrDefault(); if (obj != null) { Session["UserID"] = obj.Id.ToString(); Session["UserName"] = obj.UserName.ToString(); Session["UserRole"] = obj.UserRole.ToString(); return(RedirectToAction("Index", "Home")); } else { // ViewBag.Message = "invalid user name or password"; ModelState.AddModelError("", "Invalid User Name or Password"); } } } return(View(aUserlogin)); }
public ActionResult Create([Bind(Include = "ProductId, ReturnDate, Price, TypeReturnId")] Return newReturn) { if (ModelState.IsValid) { User user = UserEntities.GetUserByName(User.Identity.Name); newReturn.CreateDate = DateTime.Now; if (user != null) { newReturn.UserId = user.Id; } else { return(HttpNotFound()); } Product product = db.Products.Where(i => i.Id == newReturn.ProductId).FirstOrDefault(); if (product != null) { product.Count = product.Count + 1; } else { return(HttpNotFound()); } db.Returns.Add(newReturn); db.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("Create")); }
/// <summary> /// 删除实时监测数据位置信息 /// </summary> public ReturnItem <RetRealTimeMonitor> DeleteData(RealTimeMonitorModel parameter) { ReturnItem <RetRealTimeMonitor> r = new ReturnItem <RetRealTimeMonitor>(); using (UserEntities user = new UserEntities()) { try { var deletechart = user.U_HomeConfiguration.Where(s => s.ID == parameter.ID).FirstOrDefault(); if (deletechart != null) { var entry = user.Entry(deletechart); //设置该对象的状态为删除 entry.State = EntityState.Deleted; user.SaveChanges(); //保存修改 } r.Msg = "图表删除成功"; r.Code = 0; } catch (Exception e) { r.Msg = "内部错误请重试"; log.ErrorFormat("内部错误:{0},{1}", e.Message, e.StackTrace); r.Code = -1; } } return(r); }
public ActionResult ResetPassword(ResetPassword model) { var message = ""; if (ModelState.IsValid) { using (UserEntities dc = new UserEntities()) { var user = dc.Users.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault(); if (user != null) { user.Password = model.NewPassword; user.ResetPasswordCode = ""; dc.Configuration.ValidateOnSaveEnabled = false; dc.SaveChanges(); message = "Password wurde geändert "; } } } else { message = "Etwas fehlt noch !"; } ViewBag.message = message; return(View(model)); }
/// <summary> /// Code作废 /// </summary> /// <param name="Phone"></param> /// <returns></returns> public int UpdatePhoneCode(string Phone) { using (UserEntities user = new UserEntities()) { try { var getinfo = user.U_PhoneCode.Where(s => s.Phone == Phone && s.EndTime > DateTime.Now).FirstOrDefault(); if (getinfo == null) { return(0); } if (getinfo != null) { getinfo.EndTime = DateTime.Now; user.SaveChanges(); return(1); } } catch (Exception e) { return(0); } } return(0); }
public ActionResult ForgotPassword(string Email) { //Überprüfen Email // Gererate Reset Password link // send Email string message = ""; bool status = false; using (UserEntities db = new UserEntities()) { var account = db.Users.Where(a => a.Email == Email).FirstOrDefault(); if (account != null) { // senden Email für Reset Password string resetCode = Guid.NewGuid().ToString(); SendVerificationLinkEmail(account.Email, resetCode); account.ResetPasswordCode = resetCode; db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); message = " Die link für neues Password wurde an Ihre Email gesendet"; } else { message = "Konto wurde nicht gefunden !"; } } return(View()); }
public IEnumerable <User> Get() { using (UserEntities entities = new UserEntities()) { return(entities.Users.ToList()); } }
public AddUserResultCode AddUser(string emailId, string password, string firstName, string lastName, string designation, int roleId, string profilePicPath, bool enabled) { AddUserResultCode addUserResult = AddUserResultCode.Other; UserEntities user = DAO.GetUser(emailId); if (user.EmailId != null) { addUserResult = AddUserResultCode.UserAlreadyExists; } else { user = new UserEntities(); user.EmailId = emailId.Trim(); user.Password = new HashHelper().CreateHashWithSalt(password); user.FirstName = firstName.Trim(); user.LastName = lastName.Trim(); user.Designation = designation.Trim(); user.RoleId = roleId; user.ProfilePicPath = profilePicPath; user.Enabled = enabled; if (DAO.AddUser(user)) { addUserResult = AddUserResultCode.Success; } } return(addUserResult); }
public ActionResult Edit(string id, ManageUser editData) { if (ModelState.IsValid) { using (UserEntities db = new UserEntities()) { var data = db.AspNetUsers.FirstOrDefault(p => p.Id == id); if (data != default(AspNetUsers)) { data.UserName = editData.UserName; data.Email = editData.Email; db.SaveChanges(); TempData["ResultMessage"] = $"使用者{editData.UserName}編輯成功!"; return(RedirectToAction("Index")); } } } TempData["ResultMessage"] = $"資料輸入有誤,請重新輸入!"; return(View(editData)); }
public ActionResult Forgot(SignUp model) { var context = new UserEntities(); int portNumber = 587; bool enableSSL = true; string emailFromAddress = "*****@*****.**"; //Sender Email Address string emailPassword = "******"; //Sender Password string smtpAddress = "smtp.gmail.com"; string emailToAddress = model.Email; //Receiver Email Address var password = context.Users.Where(x => x.Email == model.Email).FirstOrDefault(); if (password == null) { ModelState.AddModelError("", "You Enter Wrong Email"); } string subject = "Hello " + password.UserName; string body = "Email : " + emailToAddress + "\n" + "password : "******"login")); }
public UserEntities withOutPassword() { UserEntities temp = this; temp.account.Password = null; return(temp); }
///作废TokenId用于注销登录 public ReturnItem <bool> DisableTokenId(DisableTokenIdParameter parameter) { if (parameter.TokenId == null || parameter.TokenId == "") { return(new ReturnItem <bool>() { Code = -1, Msg = "无TokenId", Data = false }); } if (parameter.UserId == null || parameter.UserId == "") { return(new ReturnItem <bool>() { Code = -1, Msg = "无user", Data = false }); } using (UserEntities user = new UserEntities()) { long temp = Convert.ToInt32(parameter.UserId); user.U_Token.Where(t => t.TokenID == parameter.TokenId && !t.IsDisabled == true && t.UserID == temp).ToList().ForEach(t => { t.IsDisabled = true; t.DisabledTime = DateTime.Now; }); user.SaveChanges(); if (CustomConfigParam.IsUseRedis) { new RedisClient(CustomConfigParam.RedisDbNumber).KeyDelete("Token:" + parameter.TokenId.Replace("-", "")); } return(new ReturnItem <bool>() { Code = 0, Msg = "欢迎再来", Data = true }); } }
public ActionResult Delete(string id) { using (UserEntities db = new UserEntities()) { //抓取對應id的資料 AspNetUsers result = (from s in db.AspNetUsers where s.Id == id select s).FirstOrDefault(); if (result != default(AspNetUsers)) //判斷是否有資料 { db.AspNetUsers.Remove(result); //儲存變更 db.SaveChanges(); //設定成功訊息 TempData["ResultMessage"] = String.Format("會員[{0}]刪除成功", result.UserName); //導向Index頁面 return(RedirectToAction("Index")); } else { TempData["ResultMessage"] = "指定資料不存在"; //導向Index頁面 return(RedirectToAction("Index")); } } }
public ActionResult Manage(ManageModel u) { if (ModelState.IsValid) { if (Session["LogedUserID"] != null) { using (UserEntities dc = new UserEntities()) { u.password = HashPassword(u.password); if (u.password.ToString().Equals((String)Session["LogedPassword"])) { int id = Convert.ToInt32(Session["LogedUserId"]); var oldUser = dc.Users.Where(model => model.id.Equals(id)).FirstOrDefault(); u.NewPassword = HashPassword(u.NewPassword); oldUser.password = u.NewPassword.ToString(); dc.SaveChanges(); ModelState.Clear(); u = null; ViewBag.Message = "Your password has been updated."; return View(); } else { ViewBag.Message = "Wrong password for user " + Session["LogedUsername"]; } } } else { return RedirectToAction("Index"); } } return View(u); }
[HttpPost] //刪除方法為POST public ActionResult Delete(string id) { using (UserEntities db = new UserEntities()) { //ProductSet內的Id = 輸入的Id 的值 var result = (from s in db.AspNetUsers where s.Id == id select s).FirstOrDefault(); if (result != default(AspNetUsers)) //如果Result有抓到資料 { db.AspNetUsers.Remove(result); db.SaveChanges(); TempData["DeleteMessage"] = String.Format("會員{0}已刪除", result.UserName); return(RedirectToAction("Index")); //回傳Result的View } else { TempData["DeleteMessage"] = "資料有誤,無法刪除,請重新操作"; return(RedirectToAction("Index")); } } }
//取得訂單中的 使用者暱稱 public string GetUserName() { //使用Order類別中的UserId到AspNetUsers資料表中搜尋出UserName using (Models.UserEntities db = new UserEntities()) { var result = (from s in db.AspNetUsers where s.Id == this.UserId select s.UserName).FirstOrDefault(); //回傳找到的UserName return result; } }