Ejemplo n.º 1
0
        public async Task <IActionResult> Patch(
            string id,
            [FromBody] UserPartialDto model
            )
        {
            await _userService.PartialUpdate(id, model);

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <bool> PartialUpdate(string id, UserPartialDto model)
        {
            var result = false;

            try
            {
                var user = await _context.Users.SingleAsync(x => x.Id == id);

                if (model.Name != null)
                {
                    user.Name = model.Name;
                }

                if (model.Lastname != null)
                {
                    user.Lastname = model.Lastname;
                }

                if (model.AboutMe != null)
                {
                    user.AboutMe = model.AboutMe;
                }

                if (model.Image != null)
                {
                    user.Image = model.Image;
                }

                _context.Update(user);
                await _context.SaveChangesAsync();

                result = true;
            }
            catch (Exception e)
            {
                // Error logging
            }

            return(result);
        }