Ejemplo n.º 1
0
        public async Task <IActionResult> AddBox([FromBody] BoxCreationData boxCreationData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var box = await _boxService.AddBox(User.GetId(), boxCreationData);

            return(CreatedAtAction(nameof(GetBox), new { boxId = box.Id }, box));
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public async Task <BoxDto> AddBox(Guid userId, BoxCreationData data)
        {
            using (Context)
            {
                var box = new Core.Data.Box
                {
                    User = await GetUserById(userId),
                    Name = data.Name
                };

                var result = await Context.AddAsync(box);

                await Context.SaveChangesAsync();

                return(result.Entity.ToBoxDto());
            }
        }