public ActionResult SendItem(int id, bool permission) { Send send = new SendResult(new PositiveResult()); var order = db.Orders.Where(i => i.Id == id).Include(i => i.ItemTransactions).FirstOrDefault(); if (permission) { foreach (var item in order.ItemTransactions) { db.Items.FirstOrDefault(i => i.Name == item.Name).Count -= item.Count; if (db.Items.FirstOrDefault(i => i.Name == item.Name).Count < 0) { send.Result = new NegativeResult(); ViewBag.Message = send.DoWork(); return(View(db.Orders.Where(i => i.To.Login == User.Identity.Name && i.Status.Name == "Sent to the warehouse").Include(i => i.ItemTransactions).Include(i => i.From).Include(i => i.Status).Include(i => i.To))); } } order.Status = db.Statuses.FirstOrDefault(i => i.Name == "Waiting for appointment"); ViewBag.Message = send.DoWork(); } else { order.Status = db.Statuses.FirstOrDefault(i => i.Name == "Renouncement"); } order.To = db.Employees.Find(order.FromId); order.From = db.Employees.FirstOrDefault(i => i.Login == User.Identity.Name); Writer.Write(order, User.Identity.Name, Server.MapPath("~/Files/")); db.SaveChanges(); return(View(db.Orders.Where(i => i.To.Login == User.Identity.Name && i.Status.Name == "Sent to the warehouse").Include(i => i.ItemTransactions).Include(i => i.From).Include(i => i.Status).Include(i => i.To))); }
public ActionResult StoreRequest(string[] counts, string[] items, string text, string to) { var order = new Order() { From = db.Employees.FirstOrDefault(i => i.Login == User.Identity.Name), To = db.Employees.FirstOrDefault(i => i.Name == db.Employees.FirstOrDefault(j => j.Name == to).Name), Text = text, Date = DateTime.Now, Status = db.Statuses.FirstOrDefault(i => i.Name == "Sent to the warehouse"), // Employee = null }; db.Orders.Add(order); for (var i = 0; i < items.Length; i++) { var item = new ItemTransaction() { Name = items[i], Count = int.Parse(counts[i]), Order = order }; db.ItemTransactions.Add(item); } db.SaveChanges(); ViewBag.Message = "Успешно добавлено!"; Writer.Write(order, User.Identity.Name, Server.MapPath("~/Files/")); return(View(db)); }
public ActionResult Create([Bind(Include = "Id,Name,Count")] Item item) { if (ModelState.IsValid) { db.Items.Add(item); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(item)); }
public bool SaveChanges() { var count = _flowContext.SaveChanges() > 0; return(count); }
public override void CreateRole(string roleName) { Role newRole = new Role() { Name = roleName }; ManageContext db = new ManageContext(); db.Roles.Add(newRole); db.SaveChanges(); }
public ActionResult Create([Bind(Include = "Id,Login,Password,Name,Age,RoleId,DepartmentId")] Employee employee) { if (ModelState.IsValid) { Employee existEmployee = db.Employees.FirstOrDefault(i => i.Login == employee.Login); if (existEmployee == null) { db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Пользователь с таким логином уже существует"); } } ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "Name", employee.Id); ViewBag.RoleId = new SelectList(db.Roles, "Id", "Name", employee.RoleId); return(View(employee)); }
public ActionResult ReturnOrders(int Id, int To, string Reason, string text) { var order = db.Orders.Find(Id); order.Text = text; order.From = db.Employees.FirstOrDefault(i => i.Login == User.Identity.Name); order.To = db.Employees.Find(To); order.Status = db.Statuses.FirstOrDefault(i => i.Name == Reason); order.Date = DateTime.Now; //order.Employee = null; db.SaveChanges(); ViewBag.Message = "Отправлено"; Writer.Write(order, User.Identity.Name, Server.MapPath("~/Files/")); return(View(db)); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { Employee Employee = null; using (ManageContext db = new ManageContext()) { Employee = db.Employees.FirstOrDefault(u => u.Login == model.Login); } if (Employee == null) { // создаем нового пользователя using (ManageContext db = new ManageContext()) { db.Employees.Add(new Employee { Login = model.Login, Password = model.Password, Role = db.Roles.Where(i => i.Name == "Admin").FirstOrDefault() }); db.SaveChanges(); Employee = db.Employees.Where(u => u.Login == model.Login && u.Password == model.Password).FirstOrDefault(); } // если пользователь удачно добавлен в бд if (Employee != null) { FormsAuthentication.SetAuthCookie(model.Login, true); return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Пользователь с таким логином уже существует"); } } return(View(model)); }
public void Update(ApplicationUser User) { _context.Update(User); _context.SaveChanges(); }
public bool SaveChanges() { return(_flowContext.SaveChanges() > 0); }