예제 #1
0
        public ActionResult <AddToCartResponseModel> AddToCart([FromBody] AddBookInputModel data)
        {
            AddToCartResponseModel res = new AddToCartResponseModel();

            try
            {
                BookBL bl   = new BookBL(DbContext);
                var    temp = bl.SaveCart(data);


                res.data = temp;

                if (temp.BookID == Guid.Empty)
                {
                    res.Message  = "Item ini sudah ada di list keranjang / list order";
                    res.Response = false;
                }
                else
                {
                    res.Message  = "Item berhasil ditambahkan di keranjang";
                    res.Response = true;
                }



                return(Ok(res));
            }
            catch (Exception ex)
            {
                res.Message  = ex.Message;
                res.Response = false;

                return(BadRequest(res));
            }
        }
        public void Add_Product_With_Invalid_Quantity_Should_Give_Errors_In_Response(int quantity)
        {
            AddToCartRequestModel addToCartRequestModel = GetAddToCartRequestModel();

            addToCartRequestModel.Quantity = quantity;

            AddToCartResponseModel expectedResponse = new AddToCartResponseModel();
            var errMsg = "Quantity should be greater than 0";

            expectedResponse.Errors.Add(errMsg);
            var response = _addToCartInteractor.Execute(addToCartRequestModel);

            response.Should().NotBeNull();
            response.Errors.Any().Should().Be(true);
            response.Errors.First().Should().Be(errMsg);
        }
        public void Add_Product_With_Invalid_ProductType_Should_Give_Errors_In_Response(string productType)
        {
            AddToCartRequestModel addToCartRequestModel = GetAddToCartRequestModel();

            addToCartRequestModel.ProductType = productType;

            AddToCartResponseModel expectedResponse = new AddToCartResponseModel();
            var errMsg = "Product does not exists in the system";

            expectedResponse.Errors.Add(errMsg);

            _productRepository.Setup(x => x.GetProduct(It.IsAny <string>(), It.IsAny <string>())).Returns((Product)null);

            var response = _addToCartInteractor.Execute(addToCartRequestModel);

            response.Should().NotBeNull();
            response.Errors.Any().Should().Be(true);
            response.Errors.First().Should().Be(errMsg);
        }
예제 #4
0
        public AddToCartResponseModel addToCart(AddToCartRequestModel addToCartRequestModel, out ErrorModel errorModel)
        {
            errorModel = null;
            AddToCartResponseModel addToCartResponseModel = null;
            SqlConnection          connection             = null;

            try
            {
                using (connection = new SqlConnection(Database.getConnectionString()))
                {
                    SqlCommand command = new SqlCommand(SqlCommands.SP_addToCart, connection);
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    #region Command Parameters
                    command.Parameters.AddWithValue("itemId", addToCartRequestModel.itemId);
                    command.Parameters.AddWithValue("addedBy", addToCartRequestModel.addedby);
                    command.Parameters.AddWithValue("qty", addToCartRequestModel.quantity);
                    #endregion
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        addToCartResponseModel               = new AddToCartResponseModel();
                        addToCartResponseModel.StatusCode    = reader["StatusCode"].ToString();
                        addToCartResponseModel.StatusMessage = reader["StatusMessage"].ToString();
                    }
                    command.Dispose();
                    return(addToCartResponseModel);
                }
            }
            catch (Exception e)
            {
                errorModel = new ErrorModel();
                errorModel.ErrorMessage = e.Message;
                return(null);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }
예제 #5
0
        public AddToCartResponseModel deleteorModifyCartItems(int cartId, int quantity, bool isDelete, out ErrorModel errorModel)
        {
            errorModel = null;
            AddToCartResponseModel addToCartResponse = null;
            SqlConnection          connection        = null;

            try
            {
                using (connection = new SqlConnection(Database.getConnectionString()))
                {
                    SqlCommand command = new SqlCommand(SqlCommands.SP_deleteorModifyCartItems, connection);
                    command.CommandType = System.Data.CommandType.StoredProcedure;

                    #region Commands Parameters

                    command.Parameters.Add(new SqlParameter("@isDelete", System.Data.SqlDbType.Bit));
                    command.Parameters["@isDelete"].Value = isDelete;

                    command.Parameters.Add(new SqlParameter("@cartId", System.Data.SqlDbType.Int));
                    command.Parameters["@cartId"].Value = cartId;

                    command.Parameters.Add(new SqlParameter("@quantity", System.Data.SqlDbType.Int));
                    command.Parameters["@quantity"].Value = quantity;

                    #endregion
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();

                    addToCartResponse = new AddToCartResponseModel();
                    if (reader.Read())
                    {
                        if (reader.isColumnExists("ErrorCode"))
                        {
                            errorModel              = new ErrorModel();
                            errorModel.ErrorCode    = reader["ErrorCode"].ToString();
                            errorModel.ErrorMessage = reader["ErrorMessage"].ToString();
                        }
                        else
                        {
                            addToCartResponse.StatusCode    = reader["StatusCode"].ToString();
                            addToCartResponse.StatusMessage = reader["StatusMessage"].ToString();
                            addToCartResponse.Total         = !string.IsNullOrEmpty(reader["Total"].ToString()) ? Convert.ToDouble(reader["Total"].ToString()) : 0;
                            addToCartResponse.Quantity      = reader["Quantity"].ToString();
                            addToCartResponse.ItemTotal     = !string.IsNullOrEmpty(reader["itemTotal"].ToString()) ? Convert.ToDouble(reader["itemTotal"].ToString()) : 0;
                        }
                    }
                    command.Dispose();
                    return(addToCartResponse);
                }
            }
            catch (Exception exception)
            {
                errorModel = new ErrorModel();
                errorModel.ErrorMessage = exception.Message;
                return(null);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }