Example #1
0
        public IActionResult AdminEdit(AdminAdminNewViewModel vm)
        {
            if (IsLogedIn() == true)
            {
                if (ModelState.IsValid)
                {
                    Admin data = vm.Admin;
                    Admin up   = _context.Admins.Where(a => a.Id == data.Id).FirstOrDefault();

                    up.Password   = data.Password;
                    up.Email      = data.Email;
                    up.Role_Id    = data.Role_Id;
                    up.DateModify = data.DateModify;

                    _context.SaveChanges();
                }

                return(View(
                           new AdminAdminNewViewModel()
                {
                    Admin = _context.Admins.Where(a => a.Id == vm.Admin.Id).FirstOrDefault(),
                    Roles = _context.Roles.OrderBy(r => r.Name)
                }));
            }
            else
            {
                return(RedirectToAction("Login"));
            }
        }
Example #2
0
 public IActionResult AdminNew(AdminAdminNewViewModel vm)
 {
     if (IsLogedIn() == true)
     {
         if (ModelState.IsValid)
         {
             _context.Admins.Add(vm.Admin);
             _context.SaveChanges();
             return(RedirectToAction("AdminsOverview"));
         }
         else
         {
             return(View(new AdminAdminNewViewModel()
             {
                 Admin = vm.Admin,
                 Roles = _context.Roles.OrderBy(r => r.Name)
             }));
         }
     }
     else
     {
         return(RedirectToAction("Login"));
     }
 }