public ActionResult edit_profile(Клиенты userprofile) { if (ModelState.IsValid) { library_globalContext db = new library_globalContext(); string username = User.Identity.Name; Клиенты user = db.Клиенты.FirstOrDefault(u => u.Login.Equals(username)); string filename = Path.GetFileNameWithoutExtension(userprofile.ImageFile.FileName); string extension = Path.GetExtension(userprofile.ImageFile.FileName); user.Имя = userprofile.Имя; user.Фамилия = userprofile.Фамилия; user.Отчество = userprofile.Отчество; user.Age = userprofile.Age; user.Адрес = userprofile.Адрес; user.Password = userprofile.Password; filename = filename + DateTime.Now.ToString("ttmmssfff") + extension; userprofile.Avatar = "~/img/avatars/" + filename; user.Avatar = filename; filename = Path.Combine(Server.MapPath("~/img/avatars"), filename); userprofile.ImageFile.SaveAs(filename); db.Клиенты.Update(user); db.SaveChanges(); return(RedirectToAction("profile", "account")); } return(View(userprofile)); }
public ActionResult profile() { string username = User.Identity.Name; library_globalContext db = new library_globalContext(); // Fetch the userprofile Клиенты user = db.Клиенты.FirstOrDefault(u => u.Login.Equals(username)); // Construct the viewmodel Клиенты model = new Клиенты(); model.Фамилия = user.Фамилия; model.Имя = user.Имя; model.Отчество = user.Отчество; model.Age = user.Age; model.Адрес = user.Адрес; model.BooksBack = user.BooksBack; model.BooksReads = user.BooksReads; model.Comments = user.Comments; model.IdКлиента = user.IdКлиента; model.Login = user.Login; model.Avatar = user.Avatar; return(View(model)); }
public ActionResult add_books(Книги books, int id_avtor) { if (ModelState.IsValid) { library_globalContext db = new library_globalContext(); Книги model = new Книги(); string filename = Path.GetFileNameWithoutExtension(books.ImageFile_add_book.FileName); string extension = Path.GetExtension(books.ImageFile_add_book.FileName); model.IdКниги = db.Книги.Max(u => u.IdКниги + 1); model.НазваниеКниги = books.НазваниеКниги; model.Описание = books.Описание; model.ДатаДобавления = DateTime.Now; model.ейтинг = 0; model.IdАвтора = id_avtor; filename = filename + DateTime.Now.ToString("ttmmssfff") + extension; books.ImgSrc = "~/img/books/" + filename; model.ImgSrc = filename; filename = Path.Combine(Server.MapPath("~/img/books"), filename); books.ImageFile_add_book.SaveAs(filename); db.Книги.Add(model); //requires using System.Data.Entity.Migrations; db.SaveChanges(); return(RedirectToAction("index", "home")); // or whatever } return(RedirectToAction("add_books", "home")); }
public ActionResult edit_profile() { string username = User.Identity.Name; library_globalContext db = new library_globalContext(); // Fetch the userprofile Клиенты user = db.Клиенты.FirstOrDefault(u => u.Login.Equals(username)); // Construct the viewmodel Клиенты model = new Клиенты(); model.Фамилия = user.Фамилия; model.Имя = user.Имя; model.Отчество = user.Отчество; model.Age = user.Age; model.Адрес = user.Адрес; model.Password = user.Password; model.Avatar = user.Avatar; return(View(model)); }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { // поиск пользователя в бд Клиенты user = null; using (library_globalContext db = new library_globalContext()) { user = db.Клиенты.FirstOrDefault(u => u.Login == model.Name && u.Password == model.Password); } if (user != null) { FormsAuthentication.SetAuthCookie(model.Name, true); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Пользователя с таким логином и паролем нет"); } } return(View(model)); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { Клиенты user = null; using (library_globalContext db = new library_globalContext()) { user = db.Клиенты.FirstOrDefault(u => u.Login == model.Name); } if (user == null) { // создаем нового пользователя using (library_globalContext db = new library_globalContext()) { int lastid = db.Клиенты.Max(u => u.IdКлиента); db.Клиенты.Add(new Клиенты { IdКлиента = lastid + 1, Login = model.Name, Password = model.Password, IdRole = 2 }); db.SaveChanges(); user = db.Клиенты.Where(u => u.Login == model.Name && u.Password == model.Password).FirstOrDefault(); } // если пользователь удачно добавлен в бд if (user != null) { FormsAuthentication.SetAuthCookie(model.Name, true); return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Пользователь с таким логином уже существует"); } } return(View(model)); }