Пример #1
0
        public async Task <IActionResult> ChangeName([FromBody] BoxChangeName data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var box = await _boxService.ChangeName(User.GetId(), data);

            return(Ok(box));
        }
Пример #2
0
        /// <inheritdoc />
        public async Task <BoxDto> ChangeName(Guid userId, BoxChangeName data)
        {
            using (Context)
            {
                //var user = await GetUserById(userId);
                var box = await Context.Boxes
                          .Include(b => b.User)
                          .Where(b => b.User.Guid == userId)
                          .FirstOrDefaultAsync();

                ExceptionExtensions.ThrowIfNull(() => box, e => new BoxNotFoundException(data.Id));

                box.Name = data.NewName;
                await Context.SaveChangesAsync();

                return(box.ToBoxDto());
            }
        }