Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Email,Password,Birthday,University,Role")] UserDescription userDescription)
        {
            if (id != userDescription.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _db.Update(userDescription);
                    _db.Save();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserDescriptionExists(userDescription.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["University"] = new SelectList(_db.GetUniversities(), "Id", "Name", userDescription.University);

            return(View(userDescription));
        }
Пример #2
0
        public int EditAccountDetailsModel(AccountDetailsModel changes, string email)
        {
            UserDescription old_user = _userRepo.GetElementByEmail(email);

            if (changes.Email.ToLower() != old_user.Email.ToLower())
            {
                var some_user = _userRepo.GetElementByEmail(changes.Email);
                if (some_user == null)
                {
                    old_user.Email = changes.Email;
                }
                else
                {
                    return(WRONG_DATA); // Почта занята
                }
            }

            if (changes.Name != old_user.Name)
            {
                old_user.Name = changes.Name;
            }

            if (changes.Date != old_user.Birthday.ToString() && !(changes.Date is null))
            {
                old_user.Birthday = DateTime.Parse(changes.Date);
            }

            if (changes.University != old_user.University)
            {
                old_user.University = changes.University;
            }

            _userRepo.Update(old_user);
            _userRepo.Save();

            return(OK);  // Изменения сохранены
        }