Beispiel #1
0
        public async Task <IResult> GetDetail(int id)
        {
            var result = new Result
            {
                Operation = Operation.Read,
                Status    = Status.Success
            };

            try
            {
                if (id != 0)
                {
                    var attrModel = await _productAttributeRepository.GetAttribute(id);

                    ProductAttributeViewModel productAttribute = new ProductAttributeViewModel();
                    productAttribute.MapFromModel(attrModel);
                    if (productAttribute != null)
                    {
                        result.Status     = Status.Success;
                        result.StatusCode = HttpStatusCode.OK;
                        result.Body       = productAttribute;
                        return(result);
                    }
                    else
                    {
                        result.Status     = Status.Fail;
                        result.StatusCode = HttpStatusCode.BadRequest;
                        result.Message    = "Attribute does not exist.";
                        return(result);
                    }
                }
                result.Status     = Status.Fail;
                result.StatusCode = HttpStatusCode.BadRequest;
                result.Message    = "Attribute ID is not valid.";
                return(result);
            }
            catch (Exception e)
            {
                result.Status     = Status.Error;
                result.Message    = e.Message;
                result.StatusCode = HttpStatusCode.InternalServerError;

                return(result);
            }
        }