public ActionResult Edit(int id, Book Book) { try { using (ISession session = NHibertnateSession.OpenSession()) { var BooktoUpdate = session.Get <Book>(id); BooktoUpdate.Name = Book.Name; BooktoUpdate.Author = Book.Author; BooktoUpdate.Publishers = Book.Publishers; using (ITransaction transaction = session.BeginTransaction()) { session.Save(BooktoUpdate); transaction.Commit(); } } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int id, Produto produto) { try { using (ISession session = NHibertnateSession.OpenSession()) { var produtoUpdate = session.Get <Produto>(id); produtoUpdate.Nome = produto.Nome; if (produtoUpdate.Valor != produto.Valor) { produtoUpdate.Valor = produto.Valor; } using (ITransaction transaction = session.BeginTransaction()) { session.Save(produtoUpdate); transaction.Commit(); } } return(RedirectToAction("Index")); } catch { return(View()); } }
public void Delete(T entity) { try { using (var session = NHibertnateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { try { session.Delete(entity); transaction.Commit(); } catch (Exception) { if (!transaction.WasCommitted) { transaction.Rollback(); } throw; } } } } catch (Exception ex) { throw ex; } }
public ActionResult Add(Document model) { try { if (!ModelState.IsValid) { return(View(model)); } var file = Request.Files[0]; if (file == null) { return(View(model)); } using (ISession session = NHibertnateSession.OpenSession()) { DateTime dateTime = DateTime.Now; string timeStamp = DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds.ToString(); var link = MD5Class.Calculate($"{timeStamp}{model.Name}").ToLower(); var fileExt = Path.GetExtension(file.FileName); var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), $"{link}{fileExt}"); file.SaveAs(path); session.CreateSQLQuery("EXEC AddDocument @name = '" + model.Name + "',@date = '" + dateTime + "',@author = '" + User.Identity.Name + "',@link = '" + link + "', @contentPath = '" + path + "'") .ExecuteUpdate(); } } catch { // ignored } return(RedirectToAction("All", "Documents")); }
public SharedGroups Update(SharedGroups entity) { try { using (var session = NHibertnateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { try { session.Update(entity); transaction.Commit(); } catch (Exception) { if (!transaction.WasCommitted) { transaction.Rollback(); } throw; } } } return(entity); } catch (Exception ex) { throw ex; } }
public ActionResult Edit(int id, Employee employee) { try { using (ISession session = NHibertnateSession.OpenSession()) { var employeetoUpdate = session.Get <Employee>(id); employeetoUpdate.Designation = employee.Designation; employeetoUpdate.FirstName = employee.FirstName; employeetoUpdate.LastName = employee.LastName; using (ITransaction transaction = session.BeginTransaction()) { session.Save(employeetoUpdate); transaction.Commit(); } } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Register(RegisterModel model) { try { User user = null; using (ISession session = NHibertnateSession.OpenSession()) { user = session.Query <User>().FirstOrDefault(u => u.Login == model.Login); } if (user == null) { using (ISession session = NHibertnateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Save(new User() { Login = model.Login, Password = MD5Class.Calculate(model.Password).ToLower() }); transaction.Commit(); FormsAuthentication.SetAuthCookie(model.Login, true); return(RedirectToAction("Index", "Home")); } } } ModelState.AddModelError("", "Пользователь с таким логином уже существует"); } catch { return(View(model)); } return(View(model)); }
public ActionResult Login(LoginModel model) { if (!ModelState.IsValid) { return(View(model)); } User user = null; using (ISession session = NHibertnateSession.OpenSession()) { user = session.Query <User>().FirstOrDefault(u => u.Login == model.Login && u.Password == MD5Class.Calculate(model.Password).ToLower()); } if (user != null) { FormsAuthentication.SetAuthCookie(model.Login, true); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Пользователя с таким логином и поролем нет"); } return(View(model)); }
public ActionResult Delete(int id) { using (ISession session = NHibertnateSession.OpenSession()) { var produto = session.Get <Produto>(id); return(View(produto)); } }
// // GET: /Book/ public ActionResult Index() { using (ISession session = NHibertnateSession.OpenSession()) { var Books = session.Query <Book>().ToList(); return(View(Books)); } }
public ActionResult Delete(int id) { using (ISession session = NHibertnateSession.OpenSession()) { var Book = session.Get <Book>(id); return(View(Book)); } }
// // GET: /Employee/ public ActionResult Index() { using (ISession session = NHibertnateSession.OpenSession()) { var employees = session.Query <Employee>().ToList(); return(View(employees)); } }
public ActionResult Delete(int id) { using (ISession session = NHibertnateSession.OpenSession()) { var employee = session.Get <Employee>(id); return(View(employee)); } }
public ActionResult Buy(int id) { var produtoPedidoModel = new ProdutoPedidoModel { }; using (ISession session = NHibertnateSession.OpenSession()) { produtoPedidoModel.Produto = session.Get <Produto>(id); return(View(produtoPedidoModel)); } }
// // GET: /SurveyForm/ public ActionResult Index() { NHibertnateSession context = new NHibertnateSession(); SurveyForm form = context.PersistenceSession .QueryOver <SurveyForm>() .Where(t => t.Title == "HOSPITAL SURVEY ON PATIENT SAFETY CULTURE") .SingleOrDefault(); return(View(form)); }
/// <summary> /// Проверка существования пользователя /// </summary> /// <param name="user">Проверяемый пользователь</param> /// <seealso cref="User"/> /// <param name="msg">Сообщение об ошибке</param> /// <returns></returns> public static bool CheckUser(User user, out string msg) { msg = string.Empty; var session = NHibertnateSession.OpenSession(); if (session == null) { msg = "Ошибка подключения к базе данных"; return(false); } User userInDb; try { userInDb = SearchUser(user, session); if (userInDb == null) { throw new Exception($"Пользователь с именем {user.Name} не найден в базе."); } Log.Info($"Пользователь {user.Name} найден в базе, необходимо выполнить проверку пароля."); } catch (Exception e) { Log.Error(e); msg = e.Message; return(false); } finally { Log.Debug("Выполняется закрытие sql-сессии"); session.Close(); Log.Debug("Закрытие sql-сессии завершено"); } Log.Debug("Производится вычисление хэша введенного пароля"); var computedHash = ComputeHash(user); Log.Debug($"Полученное значение хэша:{computedHash}"); if (computedHash.Equals(userInDb.Password)) { if (userInDb.Role != null) { Log.Info($"Пользователь {userInDb.Name} может работать с документами. Роль пользователя: {userInDb.Role.Name}"); } return(true); } msg = "Неверный пароль."; return(false); }
public ActionResult Find(string text) { List <Document> documents = new List <Document>(); if (!ModelState.IsValid || string.IsNullOrEmpty(text)) { return(View("All", documents)); } using (ISession session = NHibertnateSession.OpenSession()) { documents = session.Query <Document>().Where(d => d.Author == User.Identity.Name && d.Name.Contains(text)).ToList(); } return(View("All", documents)); }
public static string VidateUser(User user) { using (ISession session = NHibertnateSession.OpenSession()) { StringBuilder query = new StringBuilder(); query.Append("SELECT u.Username FROM User u WHERE u.Username='******' and u.Password= '******'"); var specificFields = session.CreateQuery(query.ToString()).List(); if (specificFields.Count == 1) { return("True"); } return("False"); //return View(employees); } }
public List <T> GetAll() { try { using (var session = NHibertnateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { return(session.Query <T>().ToList()); } } } catch (Exception ex) { throw ex; } }
public T GetById(object id, bool shouldLock = false) { try { using (var session = NHibertnateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { return(session.Get <T>(id)); } } } catch (Exception ex) { throw ex; } }
public ActionResult All() { Session["NameDirectSort"] = true; Session["DateDirectSort"] = true; List <Document> documents = new List <Document>(); if (!ModelState.IsValid) { return(View(documents)); } using (ISession session = NHibertnateSession.OpenSession()) { documents = session.Query <Document>().Where(d => d.Author == User.Identity.Name).ToList(); } return(View(documents)); }
public IList <Attachment> GetAllByTaskId(long taskId) { try { using (var session = NHibertnateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { return(session.QueryOver <Attachment>() .Where(t => t.TaskId == taskId).List()); } } } catch (Exception ex) { throw ex; } }
public ActionResult Delete(int id, Employee employee) { try { using (ISession session = NHibertnateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Delete(employee); transaction.Commit(); } } return(RedirectToAction("Index")); } catch (Exception exception) { return(View()); } }
public SharedGroups Find(long userId, long groupId) { try { using (var session = NHibertnateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { return(session.QueryOver <SharedGroups>() .Where(sg => sg.UserId == userId && sg.GroupId == groupId) .SingleOrDefault()); } } } catch (Exception ex) { throw ex; } }
public IList <SharedGroups> GetAllByUserId(long userId) { try { using (var session = NHibertnateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { return(session.QueryOver <SharedGroups>() .Where(sg => sg.UserId == userId && sg.IsActive) .List()); } } } catch (Exception ex) { throw ex; } }
public User FindUser(string email) { try { using (var session = NHibertnateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { return(session.QueryOver <User>() .Where(t => t.UserName == email) .SingleOrDefault()); } } } catch (Exception ex) { throw ex; } }
public Subtask Find(long taskId, string title) { try { using (var session = NHibertnateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { return(session.QueryOver <Subtask>() .Where(st => st.TaskId == taskId && st.Title == title) .SingleOrDefault()); } } } catch (Exception ex) { throw ex; } }
public IList <SharedTasks> GetAllByTaskId(long taskId) { try { using (var session = NHibertnateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { return(session.QueryOver <SharedTasks>() .Where(st => st.TaskId == taskId && st.IsActive == true) .List()); } } } catch (Exception ex) { throw ex; } }
public SharedTasks Find(long userId, long taskId) { try { using (var session = NHibertnateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { return(session.QueryOver <SharedTasks>() .Where(st => st.UserId == userId && st.TaskId == taskId) .SingleOrDefault()); } } } catch (Exception ex) { throw ex; } }
public Attachment GetAllByTaskAndName(long taskId, string name) { try { using (var session = NHibertnateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { return(session.QueryOver <Attachment>() .Where(t => t.TaskId == taskId && t.FileName == name) .SingleOrDefault()); } } } catch (Exception ex) { throw ex; } }