Exemplo n.º 1
0
        public async Task <ActionResult <ArmyListViewModel> > Create(ArmyListEditViewModel model)
        {
            var user = await GetClaimedUser();

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

            var armyList = new ArmyList(model.Name, user.Id, model.Data, DateTime.UtcNow);

            _context.ArmyLists.Add(armyList);
            await _context.SaveChangesAsync();

            return(Ok(new ArmyListViewModel(armyList)));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Update(int id, ArmyListEditViewModel model)
        {
            var user = await GetClaimedUser();

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

            var armyList = await _context.ArmyLists.FirstOrDefaultAsync(x => x.Id == id && x.User == user);

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

            armyList.Name             = model.Name;
            armyList.Data             = model.Data;
            armyList.ModificationDate = DateTime.UtcNow;
            _context.Update(armyList);
            await _context.SaveChangesAsync();

            return(Ok());
        }