Exemple #1
0
        public bool Add(AdminDto admin)
        {
            if (_users.GetAll().Any(i => i.Login == admin.Login) && !_admins.GetAll().Any(i => i.Users.Login == admin.Login))
            {
                _admins.Add(new Admins
                {
                    User_ID = _users.GetAll().First(i => i.Login == admin.Login).ID
                });

                _unitOfWork.Commit();

                return true;
            }
            else
            {
                return false;
            }
        }
Exemple #2
0
 public bool Update(AdminDto admin)
 {
     if (_admins.GetAll().Any(i => i.ID == admin.ID))
     {
         try
         {
             foreach (var item in _admins.GetAll().Where(i => i.ID == admin.ID))
             {
                 item.User_ID = _users.GetAll().First(i => i.Login == admin.Login).ID;
             }
             _unitOfWork.Commit();
         }
         catch (Exception)
         {
             return false;
         }
     }
     return false;
 }
Exemple #3
0
        public ActionResult AddAdmin(AdminViewModel adminModel)
        {
            List<string> errors;
            if (Session["val"] != null)
            {
                errors = ((string[])Session["val"]).ToList();
            }
            else
            {
                errors = new List<string>();
            }

            AdminDto _adminDto = new AdminDto();

            _adminDto.Login = adminModel.viewModel.User_Login;

            if (_adminService.Add(_adminDto))
            {
                errors.Add("Dodano administratora.");
            }
            else
            {
                errors.Add("Błąd. Spróbuj ponownie.");
            }
            Session["val"] = errors.ToArray<string>();

            return RedirectToAction("Admin");
        }