Ejemplo n.º 1
0
        public async Task <IActionResult> Partial(int id, [FromBody] ProductPartialDto model)
        {
            var result = await _productService.Partial(id, model);

            if (!result.IsSuccess)
            {
                return(StatusCode(Convert.ToInt32(HttpStatusCode.InternalServerError)));
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <ResponseHelper> Partial(int id, ProductPartialDto model)
        {
            var result = new ResponseHelper();

            try
            {
                var originalEntry = await _context.Products.SingleAsync(x => x.ProductId == id);

                originalEntry.UpdatedAt = DateTime.UtcNow;

                if (!string.IsNullOrEmpty(model.Name))
                {
                    originalEntry.Name = model.Name;
                }

                if (!string.IsNullOrEmpty(model.Description))
                {
                    originalEntry.Description = model.Description;
                }

                if (model.IsEnabled.HasValue)
                {
                    originalEntry.IsEnabled = model.IsEnabled.Value;
                }

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

                result.IsSuccess = true;
            }
            catch (Exception e)
            {
                throw;
            }
            return(result);
        }