Esempio n. 1
0
        public async Task <IActionResult> Edit(User user, string currentEmail)
        {
            if (String.IsNullOrEmpty(user.Email) && String.IsNullOrWhiteSpace(user.Email))
            {
                ModelState.AddModelError("Email", "Поле EMail не может быть пустым.");
            }
            else if (String.IsNullOrEmpty(user.FName) && String.IsNullOrWhiteSpace(user.FName))
            {
                ModelState.AddModelError("FName", "Поле фамилия не может быть пустым.");
            }
            else if (String.IsNullOrEmpty(user.MName) && String.IsNullOrWhiteSpace(user.MName))
            {
                ModelState.AddModelError("MName", "Поле имя не может быть пустым.");
            }

            if (ModelState.IsValid)
            {
                User isUniqueEmail = null;

                try
                {
                    isUniqueEmail = await _usersGRUD.CheckUniqueEmail(user, currentEmail);

                    if (isUniqueEmail == null)
                    {
                        _usersGRUD.Update(user);
                        await _usersGRUD.SaveChanges();

                        _logger.InfoGrud(DateTime.Now, "User", "Edit", "Edit", String.Format("{0} {1} {2} {3}", user.Email, user.FName, user.MName, user.LName));
                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorMessage(ex.Message);
                    return(BadRequest());
                }

                ModelState.AddModelError("EMail", "Данный email уже используется в системе");
            }

            return(View(user));
        }