Exemple #1
0
        public async Task <IActionResult> PutHero(int id, Hero hero)
        {
            if (id != hero.HeroId)
            {
                return(BadRequest());
            }

            _context.Entry(hero).State = EntityState.Modified;

            try
            {
                Debug.WriteLine(hero.Name);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HeroExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #2
0
        public async Task <IActionResult> PutBattleHero([FromRoute] int id, [FromBody] BattleHero battleHero)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != battleHero.battleId)
            {
                return(BadRequest());
            }

            _context.Entry(battleHero).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BattleHeroExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #3
0
        public async Task <ActionResult <Hero> > PostHero(Hero item)
        {
            _context.Heroes.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetHero), new { id = item.Id }, item));
        }
Exemple #4
0
        public async Task <ActionResult <Hero> > Create(Hero hero)
        {
            _context.Heroes.Add(hero);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), new { id = hero.Id }, hero));
        }
        public async Task <IActionResult> PutMainAttribute(int id, Mainattribute mainAttribute)
        {
            if (id != mainAttribute.MainattributeId)
            {
                return(BadRequest());
            }

            _context.Entry(mainAttribute).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MainAttributeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutTodoItem(long id, Hero todoItem)
        {
            if (id != todoItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(todoItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HeroExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #7
0
        public async Task <IActionResult> PutSecretIdentity([FromRoute] int id, [FromBody] SecretIdentity secretIdentity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != secretIdentity.id)
            {
                return(BadRequest());
            }

            _context.Entry(secretIdentity).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SecretIdentityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #8
0
        public async Task <Guid> CreateHeroAsync(CreateHeroRequest request)
        {
            var hero = _mapper.Map <Hero>(request);

            await _context.AddAsync(hero);

            await _context.SaveChangesAsync();

            return(hero.Id);
        }
Exemple #9
0
        public async Task <ActionResult> Create([Bind(Include = "Id,health,level,attackPower,currentExp")] Hero hero)
        {
            if (ModelState.IsValid)
            {
                db.Heroes.Add(hero);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(hero));
        }
Exemple #10
0
        public async Task <ActionResult <Hero> > Put([FromServices] HeroContext context, [FromBody] Hero model)
        {
            context.Heroes.Update(model);
            await context.SaveChangesAsync();

            return(model);
        }
Exemple #11
0
        protected override async Task Handle(HeroCommands.HeroDeleteCommand request, CancellationToken cancellationToken)
        {
            var hero = await heroDbContext.Heroes.FindAsync(request.Id);

            heroDbContext.Heroes.Remove(hero);
            await heroDbContext.SaveChangesAsync();
        }
 public async Task Execute(IJobExecutionContext context)
 {
     _logger.LogInformation("A hero was added");
     _heroContext.Heroes.Add(new Hero {
         Name = $"Superman -{DateTime.Now}"
     });
     await _heroContext.SaveChangesAsync();
 }
Exemple #13
0
        public async Task <ActionResult <Hero> > Delete(int id, [FromServices] HeroContext context)
        {
            var hero = await context.Heroes.FirstOrDefaultAsync(x => x.Id == id);

            context.Heroes.Remove(hero);
            await context.SaveChangesAsync();

            return(hero);
        }
Exemple #14
0
        public async Task <ActionResult <Hero> > Post([FromServices] HeroContext context, [FromBody] Hero model)
        {
            if (ModelState.IsValid)
            {
                context.Heroes.Add(model);
                await context.SaveChangesAsync();

                return(model);
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Exemple #15
0
        public async Task <IActionResult> Post([FromBody] RegistrationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userIdentity = _mapper.Map <ApplicationUser>(model);
            var result       = await _userManager.CreateAsync(userIdentity, model.Password);

            if (!result.Succeeded)
            {
                return(new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState)));
            }

            await _context.SaveChangesAsync();

            return(new OkObjectResult("Account created"));
        }
 protected override async Task Handle(HeroCommands.HeroCreateCommand request, CancellationToken cancellationToken)
 {
     heroDbContext.Heroes.Add(request.Hero);
     await heroDbContext.SaveChangesAsync();
 }
 public virtual async Task SaveChangesAsync()
 {
     await _context.SaveChangesAsync();
 }
 public void AddAHeroAsync(SuperHero hero)
 {
     context.Superpeople.AddAsync(mapper.ParseSuperHero(hero));
     context.SaveChangesAsync();
 }
 public async Task <Object> AddHero(Heros hero)
 {
     HeroContext.Heros.Add(hero);
     return(await HeroContext.SaveChangesAsync());
 }
 public async Task <bool> SaveChangeAsync()
 {
     return((await _context.SaveChangesAsync()) > 0);
 }
 protected override async Task Handle(HeroCommands.HeroUpdateCommand request, CancellationToken cancellationToken)
 {
     heroDbContext.Entry(request.Hero).State = EntityState.Modified;
     await heroDbContext.SaveChangesAsync();
 }