Exemple #1
0
 public ActionResult Users(UsersOrderVM model, string returnUrl = "")
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     // Update Tabella users_orders
     foreach (var item in model.Users)
     {
         using (var _db = new DAL.GestionaleDB())
         {
             var entity = db.UsersOrders.Find(model.OrderId, item.UserId);
             if (entity == null && item.Selected) //Aggiungo
             {
                 db.UsersOrders.Add(new UserOrder {
                     OrderId = model.OrderId, UserId = item.UserId
                 });
                 db.SaveChanges();
             }
             else if (entity != null && !item.Selected)
             {
                 db.Entry(entity).State = EntityState.Deleted;
                 db.SaveChanges();
             }
         }
     }
     return(RedirectToLocal(returnUrl));
 }
Exemple #2
0
        public ActionResult Users(string id, string returnUrl = "")
        {
            var order = db.Orders.Find(id);

            if (order == null)
            {
                return(HttpNotFound());
            }
            var model = new UsersOrderVM();

            model.OrderId          = order.OrderId;
            model.OrderClient      = order.Client;
            model.OrderDescription = order.Description;
            model.Users            = db.Users.Where(x => x.UserId != order.TeamLeaderId && x.RoleId != 1)
                                     .Select(x => new UserOrderVM {
                UserId   = x.UserId,
                UserInfo = x.FirstName + " " + x.LastName,
                Selected = db.UsersOrders.Any(o => o.UserId == x.UserId && o.OrderId == order.OrderId)
            });
            ViewBag.returnUrl = returnUrl;
            return(View(model));
        }