Ejemplo n.º 1
0
        public async Task <IActionResult> PutAssortmentProduct(int id, AssortmentProduct assortmentProduct)
        {
            try
            {
                if (id != assortmentProduct.ProductId)
                {
                    return(BadRequest());
                }

                _context.Entry(assortmentProduct).State = EntityState.Modified;

                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AssortmentProductExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(NoContent());
            }
            catch (NullReferenceException exception)
            {
                var nullpointerException = new ResponseMessage <string>();
                nullpointerException.Message = ApiConstants.NULL_POINTER_EXCEPTION_OCCURED;
                nullpointerException.Code    = 500;
                nullpointerException.Result  = exception.Message;
                return(BadRequest(nullpointerException));
            }
            catch (Exception exception)
            {
                var generalException = new ResponseMessage <string>();
                generalException.Message = ApiConstants.UNHANDELED_EXCEPTION_MESSAGE;
                generalException.Code    = 500;
                generalException.Result  = exception.Message;
                return(BadRequest(generalException));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <AssortmentProduct> > AddAssortmentProduct(AssortmentProduct assortmentProduct)
        {
            try {
                if (assortmentProduct.ProductId <= 0 || assortmentProduct.AssrtmntId <= 0)
                {
                    var responesMessage = new ResponseMessage <string>();
                    responesMessage.Message = ApiConstants.API_MODEL_ERROR;
                    return(BadRequest(responesMessage));
                }
                _context.AssortmentProducts.Add(assortmentProduct);
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateException)
                {
                    if (AssortmentProductExists(assortmentProduct.ProductId))
                    {
                        return(Conflict());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(CreatedAtAction("GetAssortmentProduct", new { id = assortmentProduct.ProductId }, assortmentProduct));
            }
            catch (NullReferenceException exception)
            {
                var nullpointerException = new ResponseMessage <string>();
                nullpointerException.Message = ApiConstants.NULL_POINTER_EXCEPTION_OCCURED;
                nullpointerException.Code    = 500;
                nullpointerException.Result  = exception.Message;
                return(BadRequest(nullpointerException));
            }
            catch (Exception exception)
            {
                var generalException = new ResponseMessage <string>();
                generalException.Message = ApiConstants.UNHANDELED_EXCEPTION_MESSAGE;
                generalException.Code    = 500;
                generalException.Result  = exception.Message;
                return(BadRequest(generalException));
            }
        }