Beispiel #1
0
        public async Task <IActionResult> Put(int id, [FromBody] DTO.OpeningPeriod dto)
        {
            Model.OpeningPeriod entity = await FindOpeningPeriodById(id);

            if (entity == null)
            {
                return(NotFound());
            }
            //fixme: comment améliorer cette implémentation?
            entity.Closing = dto.Closing;
            entity.Day     = dto.Day;
            entity.Opening = dto.Opening;
            await _context.SaveChangesAsync();

            return(Ok());
        }
Beispiel #2
0
        public async Task <IActionResult> Post(int shopId, [FromBody] DTO.OpeningPeriod dto)
        {
            Model.Shop shop = await FindShopById(shopId);

            if (shop == null)
            {
                return(NotFound());
            }
            int userId = int.Parse(User.Claims.First(c => c.Type == PrivateClaims.UserId).Value);

            #region ...
            if (!User.IsInRole(Constants.Roles.Admin) && shop.OwnerId != userId)
            {
                return(Forbid());
            }
            #endregion

            Model.OpeningPeriod entity = CreateEntityFromDTO(dto);
            shop.AddOpeningPeriod(entity);
            await _context.SaveChangesAsync();

            return(Created($"api/{entity.Id}", CreateDTOFromEntity(entity)));
        }
Beispiel #3
0
 private Model.OpeningPeriod CreateEntityFromDTO(DTO.OpeningPeriod dto)
 {
     return(new Model.OpeningPeriod(dto.Opening, dto.Closing, dto.Day));
 }