Exemple #1
0
        public async Task <IActionResult> Put([FromBody] BusinessPointView bpv)
        {
            var result = await _ctx.BusinessPoints.Include(bp => bp.Owner)
                         .Where(bp => bp.Id == bpv.Id)
                         .SingleOrDefaultAsync();

            if (await IsOwner(result))
            {
                result.Name     = bpv.Name;
                result.Location = bpv.Location;
                result.Price    = bpv.Price;
                result.Duration = bpv.Duration;
                await _ctx.SaveChangesAsync();

                return(Ok(bpv));
            }
            return(BadRequest(bpv));
        }
Exemple #2
0
        public async Task <IActionResult> Post([FromBody] BusinessPointView bpv)
        {
            var user = await _userManager.GetUserAsync(User);

            BusinessPoint bp = new BusinessPoint {
                Name     = bpv.Name,
                Location = bpv.Location,
                Price    = bpv.Price,
                Duration = bpv.Duration,
                Owner    = user
            };

            _ctx.Add(bp);
            var result = await _ctx.SaveChangesAsync();

            if (result > 0)
            {
                bpv.Id = bp.Id;
                return(CreatedAtAction(nameof(Get), new { id = bp.Id }, bpv));
            }
            return(BadRequest(bpv));
        }