Esempio n. 1
0
        public async Task <IActionResult> Create(GroupBetViewModel model)
        {
            if (ModelState.IsValid)
            {
                var path = string.Empty;

                if (model.LogoFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(model.LogoFile, "GroupBets");
                }

                var GroupBet = _converterHelper.ToGroupBet(model, path, true);
                _context.Add(GroupBet);
                try
                {
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.Message.Contains("duplicate"))
                    {
                        ModelState.AddModelError(string.Empty, "Este Grupo ya existe");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.InnerException.Message);
                    }
                }
            }

            return(View(model));
        }
Esempio n. 2
0
 public GroupBet ToGroupBet(GroupBetViewModel model, string path, bool isNew)
 {
     return(new GroupBet
     {
         Id = isNew ? 0 : model.Id,
         LogoPath = path,
         CreationDate = model.CreationDate,
         Admin = model.Admin,
         Tournament = model.Tournament,
         GroupBetPlayers = model.GroupBetPlayers,
         Name = model.Name
     });
 }
Esempio n. 3
0
        // GET: GroupBets/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            GroupBet GroupBetEntity = await _context.GroupBets.FindAsync(id);

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

            GroupBetViewModel model = _converterHelper.ToGroupBetViewModel(GroupBetEntity);

            return(View(model));
        }