Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("VideoID,VideoLink,Title,Image,Date,MatchID")] Video video)
        {
            if (ModelState.IsValid)
            {
                video.Date = DateTime.Now;

                if (string.IsNullOrEmpty(video.Title) || string.IsNullOrEmpty(video.Image))
                {
                    var request  = new HttpRequestMessage(HttpMethod.Get, video.VideoLink);
                    var client   = _clientFactory.CreateClient();
                    var response = await client.SendAsync(request);

                    if (response.IsSuccessStatusCode)
                    {
                        var doc = new HtmlDocument();
                        doc.LoadHtml(await response.Content.ReadAsStringAsync());

                        video.Image = doc.DocumentNode.SelectSingleNode("//meta[@property='og:image']")?.GetAttributeValue("content", "");
                        video.Title = doc.DocumentNode.SelectSingleNode("//meta[@name='title']")?.GetAttributeValue("content", "");
                    }
                }

                _context.Add(video);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MatchID"] = new SelectList(_context.Matchs, "MatchID", "Name", video.MatchID);
            return(View(video));
        }
Esempio n. 2
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. 3
0
        public async Task <IActionResult> Create(User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("ContentBlockID,Kind,Title,OrderNum,Content")] ContentBlock contentBlock)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contentBlock);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(contentBlock));
        }
Esempio n. 5
0
        public async Task <IActionResult> Create([Bind("DocumentID,Type,Link,Title,Date,MatchID")] Document document)
        {
            if (ModelState.IsValid)
            {
                document.Date = DateTime.Now;
                _context.Add(document);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MatchID"] = new SelectList(_context.Matchs, "MatchID", "Name", document.MatchID);
            return(View(document));
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("NewsID,Title,Content,MatchID")] News news)
        {
            if (ModelState.IsValid)
            {
                news.Date       = DateTime.Now;
                news.LastUpdate = news.Date;
                _context.Add(news);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MatchID"] = new SelectList(_context.Matchs, "MatchID", "Name", news.MatchID);
            return(View(news));
        }
        public async Task <IActionResult> Create(MatchTechnicalInfos matchTechnicalInfos, IFormFile modpack)
        {
            if (ModelState.IsValid)
            {
                await ProcessModpack(matchTechnicalInfos, modpack);

                _context.Add(matchTechnicalInfos);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(AdminMatchsController.Details), ControllersName.AdminMatchs, new { id = matchTechnicalInfos.MatchID }));
            }
            await LoadInformations(matchTechnicalInfos);

            return(View(matchTechnicalInfos));
        }
Esempio n. 8
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));
        }
        public async Task <IActionResult> Create(RoundSquadFormViewModel vm)
        {
            await PrepareViewModel(vm);

            if (ModelState.IsValid)
            {
                for (int i = 0; i < vm.Squad.Slots.Count; ++i)
                {
                    var slot = vm.Squad.Slots[i];
                    slot.Squad = vm.Squad;
                }
                using (var transac = await _context.Database.BeginTransactionAsync())
                {
                    if (await CheckUserAvailibilty(vm))
                    {
                        await PrepareDrowndownList(vm);

                        return(View(vm));
                    }

                    await ComputeSquadNumber(vm.Squad);

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

                    NormalizeSlotsNumber(vm);

                    _context.Add(vm.Squad);

                    foreach (var slot in vm.Squad.Slots)
                    {
                        _context.Add(slot);
                    }

                    await _context.SaveChangesAsync();

                    await transac.CommitAsync();
                }
                return(RedirectToRound(vm.Squad));
            }
            await PrepareDrowndownList(vm);

            return(View(vm));
        }
Esempio n. 10
0
        private async Task DuplicateSquadsAndSlots(RoundSide source, RoundSide target, bool includeUser)
        {
            _context.RemoveRange(target.Squads);

            target.Squads = source.Squads.Select(s => DuplicateSquadAndSlots(target, s, includeUser)).ToList();

            _context.AddRange(target.Squads);

            await _context.SaveChangesAsync();
        }
        public async Task <IActionResult> Create(MatchUserCreateViewModel vm)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vm.MatchUser);

                await _context.SaveChangesAsync();

                using (var transac = await _context.Database.BeginTransactionAsync())
                {
                    await ApplyUserSlots(vm);

                    await _context.SaveChangesAsync();

                    await transac.CommitAsync();
                }

                return(RedirectToAction(nameof(Details), ControllersName.AdminMatchs, new { id = vm.MatchUser.MatchID }, "users"));
            }
            PrepareEditViewModel(vm);
            return(View(vm));
        }