예제 #1
0
        public async Task <IResult> Insert(ProductAttributeViewModel productAttribute)
        {
            var result = new Result
            {
                Operation = Operation.Create,
                Status    = Status.Success
            };

            try
            {
                var attributeNameCheck = await _productAttributeRepository.CheckExistingAttribute(productAttribute.AttributeName);

                if (!attributeNameCheck)
                {
                    result.Status     = Status.Fail;
                    result.StatusCode = HttpStatusCode.BadRequest;
                    result.Message    = "isPresent";
                    return(result);
                }
                productAttribute.CreatedDate = DateTime.Now;
                productAttribute.CreatedBy   = _specificClaim.GetSpecificClaim("Id");
                ProductAttributeModel attributeModel = new ProductAttributeModel();
                attributeModel.MapFromViewModel(productAttribute);

                var addAttr = await _productAttributeRepository.InsertAttribute(attributeModel);

                return(addAttr);
            }
            catch (Exception e)
            {
                result.Status     = Status.Error;
                result.Message    = e.Message;
                result.StatusCode = HttpStatusCode.InternalServerError;

                return(result);
            }
        }