コード例 #1
0
        public async Task <ActionResult <ReturnResponse> > PostCustomerCartItem([FromBody] CustomerCartItemRequest customerCartItemRequest)
        {
            var dbTransaction = await _dataContext.Database.BeginTransactionAsync();

            var result = await _customerCartItemRepository.CreateCustomerCartItem(customerCartItemRequest);

            if (result.StatusCode == Utils.Success)
            {
                result.ObjectValue = _mapper.Map <CustomerCartItemResponse>((CustomerCartItem)result.ObjectValue);
                await dbTransaction.CommitAsync();

                return(StatusCode(StatusCodes.Status200OK, result));
            }
            else
            {
                await dbTransaction.RollbackAsync();

                return(StatusCode(StatusCodes.Status400BadRequest, result));
            }
        }
コード例 #2
0
        public async Task <ReturnResponse> CreateCustomerCartItem(CustomerCartItemRequest customerCartItemRequest)
        {
            if (customerCartItemRequest == null)
            {
                return(new ReturnResponse()
                {
                    StatusCode = Utils.ObjectNull,
                    StatusMessage = Utils.StatusMessageObjectNull
                });
            }

            var loggedInUser = _globalRepository.GetUserInformation();

            if (loggedInUser.UserTypeId == Utils.UserClaim_Null)
            {
                return(new ReturnResponse()
                {
                    StatusCode = Utils.UserClaimNotFound,
                    StatusMessage = Utils.StatusMessageUserClaimNotFound
                });
            }

            var customerCartItem = _mapper.Map <CustomerCartItem>(customerCartItemRequest);

            customerCartItem.CustomerId = loggedInUser.UserTypeId;

            var creationResult = _globalRepository.Add(customerCartItem);

            if (!creationResult)
            {
                return(new ReturnResponse()
                {
                    StatusCode = Utils.NotSucceeded,
                    StatusMessage = Utils.StatusMessageNotSucceeded
                });
            }

            var saveResult = await _globalRepository.SaveAll();

            if (!saveResult.HasValue)
            {
                return(new ReturnResponse()
                {
                    StatusCode = Utils.SaveError,
                    StatusMessage = Utils.StatusMessageSaveError
                });
            }

            if (!saveResult.Value)
            {
                return(new ReturnResponse()
                {
                    StatusCode = Utils.SaveNoRowAffected,
                    StatusMessage = Utils.StatusMessageSaveNoRowAffected
                });
            }

            return(new ReturnResponse()
            {
                StatusCode = Utils.Success,
                StatusMessage = Utils.StatusMessageSuccess,
                ObjectValue = customerCartItem
            });
        }