Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, User user)
        {
            if (id != user.UserID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.UserID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Esempio n. 2
0
        public async Task <IActionResult> Password([Bind("Login,OldPassword,Password,PasswordRepeat")] PasswordViewModel vm)
        {
            var user = await UserHelper.GetUser(_context, User);

            if (user == null)
            {
                return(NotFound());
            }
            var userPwd = await _context.UserLogins.FirstOrDefaultAsync(u => u.UserID == user.UserID);

            if (vm.Password != vm.PasswordRepeat)
            {
                ModelState.AddModelError("PasswordRepeat", "Les deux mots de passe ne correspondent pas.");
            }
            else if (await _context.UserLogins.AnyAsync(u => u.UserID != user.UserID && u.Login.ToLower() == vm.Login.ToLower()))
            {
                ModelState.AddModelError("Login", "Le nom d'utilisateur est déjà utilisé.");
            }
            else if (userPwd != null && !userPwd.IsValidPassword(vm.OldPassword))
            {
                ModelState.AddModelError("OldPassword", "L'ancien mot de passe ne corresponds pas.");
            }
            else if (ModelState.IsValid)
            {
                if (userPwd != null)
                {
                    userPwd.Login = vm.Login;
                    userPwd.SetPassword(vm.Password);
                    _context.Update(userPwd);
                }
                else
                {
                    userPwd        = new UserLogin();
                    userPwd.UserID = user.UserID;
                    userPwd.Login  = vm.Login;
                    userPwd.SetPassword(vm.Password);
                    _context.Add(userPwd);
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            vm.OldPassword     = string.Empty;
            vm.Password        = string.Empty;
            vm.PasswordRepeat  = string.Empty;
            vm.NeedOldPassword = userPwd != null;
            return(View(vm));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("NewsID,Title,Content,Date,MatchID")] News news)
        {
            if (id != news.NewsID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    news.LastUpdate = DateTime.Now;
                    _context.Update(news);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NewsExists(news.NewsID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MatchID"] = new SelectList(_context.Matchs, "MatchID", "Name", news.MatchID);
            return(View(news));
        }
Esempio n. 4
0
        public async Task <IActionResult> Edit(int id, [Bind("VideoID,VideoLink,Title,Image,Date,MatchID")] Video video)
        {
            if (id != video.VideoID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(video);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VideoExists(video.VideoID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MatchID"] = new SelectList(_context.Matchs, "MatchID", "Name", video.MatchID);
            return(View(video));
        }
Esempio n. 5
0
        public async Task <IActionResult> Edit(int id, [Bind("ContentBlockID,Kind,Title,OrderNum,Content")] ContentBlock contentBlock)
        {
            if (id != contentBlock.ContentBlockID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(contentBlock);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ContentBlockExists(contentBlock.ContentBlockID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(contentBlock));
        }
Esempio n. 6
0
        public async Task <IActionResult> Edit(int id, [Bind("DocumentID,Type,Link,Title,Date,MatchID")] Document document)
        {
            if (id != document.DocumentID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(document);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DocumentExists(document.DocumentID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MatchID"] = new SelectList(_context.Matchs, "MatchID", "Name", document.MatchID);
            return(View(document));
        }
Esempio n. 7
0
        public async Task <IActionResult> SubscriptionSide(int id, int matchSideID)
        {
            var user = await GetUser();

            if (user == null)
            {
                return(NotFound());
            }

            var matchUser = await _context.MatchUsers.FirstOrDefaultAsync(u => u.MatchID == id && u.UserID == user.UserID);

            if (matchUser == null || matchUser.MatchSideID != null)
            {
                return(NotFound());
            }

            matchUser.MatchSideID = await _context.MatchSides.Where(s => s.MatchSideID == matchSideID && s.MatchID == id).Select(s => s.MatchSideID).FirstOrDefaultAsync();

            if (matchUser.MatchSideID != null)
            {
                using (var transaction = await _context.Database.BeginTransactionAsync())
                {
                    if (await CanJoin(matchUser))
                    {
                        _context.Update(matchUser);
                        await _context.SaveChangesAsync();

                        await transaction.CommitAsync();
                    }
                }
            }
            return(RedirectToAction(nameof(Subscription), new { id }));
        }
Esempio n. 8
0
        public async Task <IActionResult> SetUserSide(int matchUserId, [FromForm] int matchSideId)
        {
            var matchUser = await _context.MatchUsers.FindAsync(matchUserId);

            matchUser.MatchSideID = matchSideId;

            _context.Update(matchUser);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Details), ControllersName.AdminMatchs, new { id = matchUser.MatchID }, "unassigned"));
        }
        public async Task <IActionResult> Edit(int id, MatchUserEditViewModel vm)
        {
            if (id != vm.MatchUser.MatchUserID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    using (var transac = await _context.Database.BeginTransactionAsync())
                    {
                        _context.Update(vm.MatchUser);

                        await ApplyUserSlots(vm);

                        await _context.SaveChangesAsync();

                        await transac.CommitAsync();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MatchUserExists(vm.MatchUser.MatchUserID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Details), ControllersName.AdminMatchs, new { id = vm.MatchUser.MatchID }, "users"));
            }
            PrepareEditViewModel(vm);
            return(View(vm));
        }
        public async Task <IActionResult> Edit(int id, MatchTechnicalInfos matchTechnicalInfos, IFormFile modpack)
        {
            if (id != matchTechnicalInfos.MatchTechnicalInfosID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (!await ProcessModpack(matchTechnicalInfos, modpack))
                    {
                        var existing = await _context.MatchTechnicalInfos.AsNoTracking().FirstAsync(i => i.MatchTechnicalInfosID == matchTechnicalInfos.MatchTechnicalInfosID);

                        matchTechnicalInfos.ModsCount      = existing.ModsCount;
                        matchTechnicalInfos.ModsDefinition = existing.ModsDefinition;
                        matchTechnicalInfos.ModsLastChange = existing.ModsLastChange;
                    }

                    _context.Update(matchTechnicalInfos);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MatchTechnicalInfosExists(matchTechnicalInfos.MatchTechnicalInfosID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(AdminMatchsController.Details), ControllersName.AdminMatchs, new { id = matchTechnicalInfos.MatchID }));
            }
            await LoadInformations(matchTechnicalInfos);

            return(View(matchTechnicalInfos));
        }
Esempio n. 11
0
        public async Task <IActionResult> Edit(int id, RoundSquadFormViewModel vm)
        {
            if (id != vm.Squad.RoundSquadID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    using (var transac = await _context.Database.BeginTransactionAsync())
                    {
                        await PrepareViewModel(vm);

                        var removed = vm.Squad.Slots.Where(s => s.Role == null && s.RoundSlotID != 0).ToList();

                        // Il y a un risque de concurrence d'accès, on s'assure que si un utilisateur s'est affecté entre temps que ce n'est pas perdu
                        if (await DetectConcurrentUpdates(vm) || await CheckUserAvailibilty(vm))
                        {
                            await PrepareDrowndownList(vm);

                            return(View(vm));
                        }

                        vm.Squad.Slots      = vm.Squad.Slots.Where(s => s.Role != null).ToList();
                        vm.Squad.SlotsCount = vm.Squad.Slots.Count();
                        _context.Update(vm.Squad);

                        // Numérote les slots, et s'assure que les utilisateurs n'ont pas de doublons
                        NormalizeSlotsNumber(vm);

                        foreach (var slot in vm.Squad.Slots)
                        {
                            slot.SetTimestamp();
                            if (slot.RoundSlotID == 0)
                            {
                                _context.Add(slot);
                            }
                            else
                            {
                                _context.Update(slot);
                            }
                        }

                        foreach (var slot in removed)
                        {
                            _context.Remove(slot);
                        }

                        await _context.SaveChangesAsync();

                        await transac.CommitAsync();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RoundSquadExists(vm.Squad.RoundSquadID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToRound(vm.Squad));
            }
            await PrepareViewModel(vm);
            await PrepareDrowndownList(vm);

            return(View(vm));
        }