Пример #1
0
        public async Task <IActionResult> EditTraining(int id, /*[Bind("ID,Title,ReleaseDate,Genre,Price")] */ ControleTraining edtraining)
        {
            if (id != edtraining.TrainingId)
            {
                return(NotFound());
            }


            if (ModelState.IsValid)
            {
                Training trainingCh = await _context.Trainings.FirstOrDefaultAsync(u => u.Name == edtraining.Name& u.TrainingId != edtraining.TrainingId);

                if (trainingCh == null)
                {
                    try
                    {
                        Training training = new Training();
                        DateTime datetime = new DateTime(edtraining.TimeOfStarting.Year, edtraining.TimeOfStarting.Month, edtraining.TimeOfStarting.Day,
                                                         edtraining.Time.Hour, edtraining.Time.Minute, edtraining.Time.Second);
                        training.TimeOfStarting   = datetime;
                        training.Name             = edtraining.Name;
                        training.TrainingDuration = edtraining.TrainingDuration;
                        training.TrainingId       = edtraining.TrainingId;
                        training.GymId            = edtraining.GymId;
                        _context.Update(training);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        Training trainingCheck = await _context.Trainings.FirstOrDefaultAsync(u => u.TrainingId == edtraining.TrainingId);

                        if (trainingCheck == null)

                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                    return(await EditTraining(id));
                }
            }
            return(RedirectToAction(nameof(ControleTraining)));
        }
Пример #2
0
        public async Task <IActionResult> ChooseMemberTicket(int id)
        {
            if (id == null)
            {
                return(RedirectToAction(nameof(ControlMemberTicket)));
            }

            User AuthUser = await _context.Users.FirstOrDefaultAsync(u => u.Login == User.Identity.Name.ToString());

            var mems = await _context.MemberTickets
                       .FirstOrDefaultAsync(m => m.MemberTicketId == id);

            if (mems != null)
            {
                AuthUser.MemberTicketId = id;
            }
            AuthUser.ConclusionDate = DateTime.Now.Date;
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(ControlMemberTicket)));
        }
Пример #3
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _context.Users.FirstOrDefaultAsync(u => u.Login == model.Login);

                if (user == null)
                {
                    // добавляем пользователя в бд
                    user = new User
                    {
                        Login        = model.Login,
                        Password     = model.Password,
                        LastName     = model.LastName,
                        FirstName    = model.FirstName,
                        Patronymic   = model.Patronymic,
                        PassportData = model.PassportData
                    };

                    Role userRole = await _context.Roles.FirstOrDefaultAsync(r => r.Name == model.AccountType);

                    if (userRole != null)
                    {
                        user.Role   = userRole;
                        user.RoleId = userRole.RoleId;
                    }
                    _context.Users.Add(user);
                    await _context.SaveChangesAsync();

                    await Authenticate(user); // аутентификация

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                    return(View(model));
                }
            }
            ModelState.AddModelError("", "Не прошел валидацию");
            return(View(model));
        }
Пример #4
0
        public async Task <IActionResult> EditUser(int id, /*[Bind("ID,Title,ReleaseDate,Genre,Price")] */ User user)
        {
            if (id != user.UserId)
            {
                return(NotFound());
            }


            if (ModelState.IsValid)
            {
                User userCh = await _context.Users.FirstOrDefaultAsync(u => u.Login == user.Login& u.UserId != user.UserId);

                if (userCh == null)
                {
                    try
                    {
                        _context.Update(user);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        User userCheck = await _context.Users.FirstOrDefaultAsync(u => u.UserId == user.UserId);

                        if (userCheck == null)

                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                    return(await EditUser(id));
                }
            }
            return(RedirectToAction(nameof(EditDB)));
        }