public ActionResult ChangePassword(PasswordChangeEntity pasEntity) { User user = (User)Session["User"]; byte[] pas = Encoding.Unicode.GetBytes(pasEntity.OldPassword); SHA1 sha = new SHA1CryptoServiceProvider(); pas = sha.ComputeHash(pas); if (!pas.SequenceEqual(user.Password)) { return(ErrorView("Невено введён пароль")); } if (String.Compare(pasEntity.NewPassword, pasEntity.RepeatNewPassword, false) != 0) { return(ErrorView("Вы неправильно повторили пароль")); } pas = Encoding.Unicode.GetBytes(pasEntity.NewPassword); user.Password = sha.ComputeHash(pas); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); Session["User"] = user; ViewBag.SelectedUser = user; ViewBag.User = user; return(View("PersonalArea")); }
public async Task <IActionResult> PutEmployeeOwner([FromBody] EmployeeOwner employeeOwner, [FromHeader] string Authorization) { string token = Authorization.Split(' ')[1]; var user = (from bb in _context.Auths join aa in _context.Tokens on bb.id equals aa.user_id join cc in _context.EmployeeOwners on bb.id equals cc.id_user where aa.access == token select cc).FirstOrDefault(); _context.Entry(user).State = EntityState.Modified; user.phone = employeeOwner.phone; user.lastname = employeeOwner.lastname; user.firstname = employeeOwner.firstname; user.email = user.email; try { await _context.SaveChangesAsync(); } catch (Exception ex) { return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.BadRequest, null, ex.Message))); } return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.OK, user, null))); }
public async Task <JsonResult> AddComment(int id, [FromBody] AComment value) { var day = await _context.conctereDays.FindAsync(id); _context.Entry(day).State = EntityState.Modified; day.services_comment = value.comment; await _context.SaveChangesAsync(); return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.OK, day, null))); }
public async Task <JsonResult> PutService(int id, [FromBody] SendServices service) { var ser = await _context.Services.FindAsync(id); _context.Entry(ser).State = EntityState.Modified; ser.name = service.name; ser.minutes = service.minutes; ser.price = service.price; ser.descride = service.descride; try { await _context.SaveChangesAsync(); return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.OK, service, null))); } catch (DbUpdateConcurrencyException) { if (!ServiceExists(id)) { return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.NotFound, service, null))); } else { throw; } } return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.NoContent, service, null))); }
public async Task <IActionResult> PutClient(int id, Client client) { if (id != client.id) { return(BadRequest()); } _context.Entry(client).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClientExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult PutUser(int id, User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != user.User_ID) { return(BadRequest()); } db.Entry(user).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
// PUT api/Data/5 public HttpResponseMessage PutEmployee(Int32 id, Employee employee) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != employee.Id) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } db.Entry(employee).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public async Task <RedirectResult> Activate([FromQuery] string link) { var temp = await _context.Confirms.Where(x => x.code == link).FirstOrDefaultAsync(); if (temp != null) { var user = await _context.Auths.FindAsync(temp.user_id); _context.Entry(user).State = EntityState.Modified; user.is_confirm = true; await _context.SaveChangesAsync(); return(Redirect("http://ocpio.com/confirm.html")); } return(Redirect("http://ocpio.com/")); }
public ActionResult EditService(Service service) { User user = (User)Session["User"]; if ((user == null) || (user.Role != UserRole.ADMIN)) { return(HttpNotFound()); } if ((service.Tarif != null) && (service.ConnectionType != null) && (service.Payment != null) && (service.Speed != null) && (service.Term != null) && (service.Traffic != null) && (service.SubscrCash != null) && (service.Agreement != null)) { if (service.Id != 0) { db.Entry(service).State = EntityState.Modified; db.SaveChanges(); } else { db.AllServices.Add(service); } return(RedirectToAction("Services")); } else { return(View()); } }
public async Task <JsonResult> UploadUserpic(IFormFile file, [FromHeader] string Authorization) { string token = Authorization.Split(' ')[1]; var user = from bb in _context.Auths join aa in _context.Tokens on bb.id equals aa.user_id join cc in _context.Accounts on bb.id equals cc.id_user where aa.access == token select cc; var usercheck = user.FirstOrDefault(); if (usercheck == null) { return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.NotFound, null, "Пользователь не найден"))); } var responce = await _imageHandler.UploadUserpic(file); if (responce[0] == "OK") { var checkuser = await _context.Userpics.Where(x => x.account_id == 1).FirstOrDefaultAsync(); if (checkuser == null) { Userpic userpic = new Userpic { path = responce[2], name = responce[1], dttmadd = DateTime.UtcNow, account_id = 1 }; await _context.Userpics.AddAsync(userpic); } else { System.IO.File.Delete(checkuser.path); _context.Entry(checkuser).State = EntityState.Modified; checkuser.dttmadd = DateTime.UtcNow; checkuser.name = responce[1]; checkuser.path = responce[2]; } await _context.SaveChangesAsync(); return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.OK, null, "Изображение сохранено"))); } else { //var er = _localizer["error_image"]; return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.BadRequest, responce[1], "Изображение не сохранено"))); } }