Пример #1
0
        public frmShoppingCart(string UserName, string PassWord)
        {
            this.UserName = UserName;
            this.PassWord = PassWord;
            InitializeComponent();
            DataTable dtCart = OrderItemsController.ShowCart(UserName).Tables[0];

            foreach (DataRow dr in dtCart.Rows)
            {
                string ImageTemp = dr["Image"].ToString();
                Image  image;
                if (ImageTemp != "")
                {
                    string appPath  = Application.StartupPath.Substring(0, (Application.StartupPath.Length - 10)) + @"\images\imagesProduct\";
                    string FileName = appPath + ImageTemp;
                    image = Image.FromFile(FileName);
                }
                else
                {
                    ImageTemp = "10.jpg";
                    string appPath  = Application.StartupPath.Substring(0, (Application.StartupPath.Length - 10)) + @"\images\imagesUser\";
                    string FileName = appPath + ImageTemp;
                    image = Image.FromFile(FileName);
                }
                image = new Bitmap(image, new Size(70, 70));
                string ItemName    = dr["ItemName"].ToString();
                string Description = dr["Description"].ToString();
                string PaidPrice   = dr["PaidPrice"].ToString();
                string Orgin       = dr["Orgin"].ToString();
                string Quantity    = dr["Quantity"].ToString();
                dtGVShoppingCart.Rows.Add(image, ItemName, Description, PaidPrice, Orgin, Quantity);
            }
        }
Пример #2
0
 private void Btn_Click(object sender, EventArgs e)
 {
     Guna.UI.WinForms.GunaButton btn = sender as Guna.UI.WinForms.GunaButton;
     if (UserName != "")
     {
         string UserName  = this.UserName;
         string ItemName  = btn.Text;
         float  SalePrice = float.Parse(HomeController.PriceItem(ItemName).Tables[0].Rows[0][0].ToString());
         float  Quantity  = 1;
         bool   check     = OrderItemsController.AddCart(UserName, PassWord, ItemName, SalePrice, Quantity, ref err);
         if (check == true)
         {
             MessageBox.Show("Bạn đã thêm " + ItemName + " vào giỏ hàng thành công");
             this.lblShowCart.Text = OrderItemsController.ShowTotalDetails(UserName, PassWord).Tables[0].Rows[0][0].ToString();
         }
         else
         {
             MessageBox.Show("Bạn đã thêm món ăn vào giỏ hàng thất bại");
         }
     }
     else
     {
         DialogResult dialogResult;
         dialogResult = MessageBox.Show("Mời bạn đăng nhập để sử dụng tính năng này", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
         if (dialogResult == DialogResult.OK)
         {
             this.Hide();
             frmSignIn frmSign = new frmSignIn();
             frmSign.ShowDialog();
             this.Close();
         }
     }
 }
Пример #3
0
        public static async Task ListAsync_WithFilter_ReturnsExpectedResult(
            [Frozen] Mock <IOrderItemService> service,
            [Frozen] CallOffId callOffId,
            List <OrderItem> orderItems,
            Order order,
            OrderItemsController controller)
        {
            foreach (var orderItem in orderItems)
            {
                order.AddOrUpdateOrderItem(orderItem);
            }

            const CatalogueItemType catalogueItemType = CatalogueItemType.AdditionalService;

            service.Setup(o => o.GetOrder(callOffId)).ReturnsAsync(order);
            service.Setup(o => o.GetOrderItems(callOffId, catalogueItemType)).ReturnsAsync(
                orderItems.Where(i => i.CatalogueItem.CatalogueItemType == catalogueItemType).Select(i => i).ToList());

            var expectedResult = orderItems
                                 .Where(i => i.CatalogueItem.CatalogueItemType == catalogueItemType)
                                 .Select(i => new GetOrderItemModel(i));

            var response = await controller.ListAsync(callOffId, catalogueItemType);

            response.Value.Should().BeEquivalentTo(expectedResult);
        }
Пример #4
0
        public static async Task CreateOrderItemsAsync_ValidationFailure_ReturnsExpectedResponse(
            ErrorDetails errorDetails,
            AggregateValidationResult aggregateValidationResult,
            [Frozen] Mock <ICreateOrderItemService> createOrderItemService,
            [Frozen] Mock <IOrderItemService> orderItemService,
            [Frozen] CallOffId callOffId,
            CatalogueItemId catalogueItemId,
            Order order,
            CreateOrderItemModel model,
            OrderItemsController controller)
        {
            controller.ProblemDetailsFactory = new TestProblemDetailsFactory();
            aggregateValidationResult.AddValidationResult(new ValidationResult(errorDetails), 0);

            Expression <Func <ICreateOrderItemService, Task <AggregateValidationResult> > > createAsync = s => s.CreateAsync(
                It.Is <Order>(o => o.Equals(order)),
                It.Is <CatalogueItemId>(i => i == catalogueItemId),
                It.Is <CreateOrderItemModel>(m => m == model));

            orderItemService.Setup(o => o.GetOrder(callOffId)).ReturnsAsync(order);
            createOrderItemService.Setup(createAsync).ReturnsAsync(aggregateValidationResult);

            var response = await controller.CreateOrderItemAsync(callOffId, catalogueItemId, model);

            response.Should().BeOfType <BadRequestObjectResult>();
            response.As <BadRequestObjectResult>().Value.Should().BeOfType <ValidationProblemDetails>();
        }
        public frmShipping(string UserName, string PassWord, string DefaultAddress, string PhoneNumber, string FullName)
        {
            this.UserName       = UserName;
            this.DefaultAddress = DefaultAddress;
            this.PassWord       = PassWord;
            InitializeComponent();
            this.lblAddress.Text     = DefaultAddress;
            this.lblFullName.Text    = FullName;
            this.lblPhoneNumber.Text = PhoneNumber;
            this.lblShowPrice.Text   = OrderItemsController.ShowTotalPrice(UserName, PassWord).Tables[0].Rows[0][0].ToString();
            DataTable dtAllBillDetails = OrderItemsController.ShowCart(UserName).Tables[0];
            int       ylbl             = 10;

            foreach (DataRow dr in dtAllBillDetails.Rows)
            {
                Guna.UI.WinForms.GunaLabel lbl = new Guna.UI.WinForms.GunaLabel();
                lbl.Location = new Point(8, ylbl);
                lbl.Font     = new Font("Tahoma", 9, FontStyle.Bold);
                lbl.Text     = dr["ItemName"].ToString() + " x " + dr["Quantity"].ToString() + " : \t" + dr["PaidPrice"].ToString();
                lbl.AutoSize = true;
                pnAllBillDetails.Controls.Add(lbl);

                ylbl += 24;
            }
        }
        public void UpdateOrder_OkResult()
        {
            //Arrange
            var controller  = new OrderItemsController(_uow);
            var orderItemId = 2;

            var orderItem = new OrderItem
            {
                OrderItemId = orderItemId,
                OrderId     = 3,
                ProductId   = 2,
                Quantity    = 4
            };

            //Act
            var result       = controller.Put(orderItemId, orderItem);
            var updated      = controller.Get(orderItem.OrderItemId);
            var updatedOrder = updated.Value.Should().BeAssignableTo <OrderItem>().Subject;

            //Assert
            Assert.IsType <OkResult>(result.Result);
            Assert.Equal(updatedOrder.OrderItemId, orderItem.OrderItemId);
            Assert.Equal(updatedOrder.OrderId, orderItem.OrderId);
            Assert.Equal(updatedOrder.ProductId, orderItem.ProductId);
            Assert.Equal(updatedOrder.Quantity, orderItem.Quantity);
        }
Пример #7
0
        public static async Task CreateOrderItemAsync_OrderExists_ReturnsCreatedAtActionResult(
            [Frozen] Mock <ICreateOrderItemService> createOrderItemService,
            [Frozen] Mock <IOrderItemService> orderItemService,
            [Frozen] CallOffId callOffId,
            CatalogueItemId catalogueItemId,
            Order order,
            CreateOrderItemModel model,
            OrderItemsController controller)
        {
            Expression <Func <ICreateOrderItemService, Task <AggregateValidationResult> > > createAsync = s => s.CreateAsync(
                It.Is <Order>(o => o.Equals(order)),
                It.Is <CatalogueItemId>(i => i == catalogueItemId),
                It.Is <CreateOrderItemModel>(m => m == model));

            orderItemService.Setup(o => o.GetOrder(callOffId)).ReturnsAsync(order);
            createOrderItemService.Setup(createAsync).ReturnsAsync(new AggregateValidationResult());

            var result = await controller.CreateOrderItemAsync(callOffId, catalogueItemId, model);

            result.Should().BeOfType <CreatedAtActionResult>();
            result.As <CreatedAtActionResult>().Should().BeEquivalentTo(new
            {
                ActionName  = "Get",
                RouteValues = new RouteValueDictionary
                {
                    { nameof(callOffId), callOffId.ToString() },
                    { nameof(catalogueItemId), catalogueItemId.ToString() },
                },
            });
        }
Пример #8
0
        public static async Task CreateOrderItemAsync_ValidationFailure_AddsModelErrors(
            [Frozen] IReadOnlyList <ErrorDetails> errorDetails,
            AggregateValidationResult aggregateValidationResult,
            [Frozen] Mock <ICreateOrderItemService> createOrderItemService,
            [Frozen] Mock <IOrderItemService> orderItemService,
            [Frozen] CallOffId callOffId,
            CatalogueItemId catalogueItemId,
            Order order,
            CreateOrderItemModel model,
            OrderItemsController controller)
        {
            controller.ProblemDetailsFactory = new TestProblemDetailsFactory();
            aggregateValidationResult.AddValidationResult(new ValidationResult(errorDetails), 0);

            Expression <Func <ICreateOrderItemService, Task <AggregateValidationResult> > > createAsync = s => s.CreateAsync(
                It.Is <Order>(o => o.Equals(order)),
                It.Is <CatalogueItemId>(i => i == catalogueItemId),
                It.Is <CreateOrderItemModel>(m => m == model));

            orderItemService.Setup(o => o.GetOrder(callOffId)).ReturnsAsync(order);
            createOrderItemService.Setup(createAsync).ReturnsAsync(aggregateValidationResult);

            await controller.CreateOrderItemAsync(callOffId, catalogueItemId, model);

            var modelState = controller.ModelState;

            modelState.ErrorCount.Should().Be(errorDetails.Count);
            modelState.Keys.Should().BeEquivalentTo(errorDetails.Select(e => e.ParentName + "[0]." + e.Field));

            var modelStateErrors = modelState.Values.Select(v => v.Errors[0].ErrorMessage);

            modelStateErrors.Should().BeEquivalentTo(errorDetails.Select(e => e.Id));
        }
Пример #9
0
        private void btnOrderCart_Click(object sender, EventArgs e)
        {
            this.Hide();
            DataTable dtIDUser = OrderItemsController.IDUser_Find(UserName, PassWord).Tables[0];
            string    IDUser   = dtIDUser.Rows[0][0].ToString();

            string Roles          = UserController.ShowRole(UserName).Tables[0].Rows[0][0].ToString();
            string DefaultAddress = "";
            string PhoneNumber    = "";
            string FullName       = "";

            if (Roles == "Seller")
            {
                DefaultAddress = "105 Đường 11, phường Tăng Nhơn Phú B, Quận 9, Thành phố Hồ Chí Minh";
                PhoneNumber    = "0333963285";
                FullName       = UserName;
            }
            else
            {
                DataTable dtAddress_User = OrderItemsController.All_Address_Show(IDUser, UserName, PassWord).Tables[0];
                foreach (DataRow dr in dtAddress_User.Rows)
                {
                    if (dr["IsDefault"].ToString() == "1")
                    {
                        DefaultAddress = dr["Street"].ToString() + ", " + dr["Ward"].ToString() + ", " + dr["District"].ToString() + ", " + dr["Province"].ToString();
                        PhoneNumber    = dr["PhoneNumber"].ToString();
                        FullName       = dr["FullName"].ToString();
                    }
                }
            }
            frmShipping frmShip = new frmShipping(UserName, PassWord, DefaultAddress, PhoneNumber, FullName);

            frmShip.ShowDialog();
        }
        public OrderItemsControllerUnitTest()
        {
            _mockLogger = new Mock <ILogger <OrderItemsController> >();

            _orders      = new List <Order>();
            _orderItem22 = new OrderItem
            {
                Id        = 22,
                Quantity  = 17,
                UnitPrice = 12
            };
            _orders.Add(new Order
            {
                Id    = 1,
                Items = new List <OrderItem>(new OrderItem[] {
                    new OrderItem {
                        Id        = 20,
                        Quantity  = 10,
                        UnitPrice = 30
                    },
                    new OrderItem {
                        Id        = 21,
                        Quantity  = 15,
                        UnitPrice = 45
                    },
                    _orderItem22
                }),

                OrderDate   = DateTime.Now,
                OrderNumber = "12345",
                User        = new StoreUser()
            });


            _mockRepo = new Mock <IDutchRepository>();
            _mockRepo.Setup(r => r.GetOrderById(It.IsAny <string>(), It.IsAny <int>()))
            .Returns <string, int>((username, id) =>
                                   _orders.FirstOrDefault(order => order.Id == id)
                                   );


            _orderItemsViewModel = new List <OrderItemViewModel>();
            _orderItemsViewModel.Add(new OrderItemViewModel
            {
                Id        = 123,
                Quantity  = 10,
                UnitPrice = 25
            });

            _mockMapper = new Mock <IMapper>();
            _mockMapper.Setup(m => m.Map <IEnumerable <OrderItem>, IEnumerable <OrderItemViewModel> >(_orders[0].Items))
            .Returns(_orderItemsViewModel);

            var httpContextBuilder = new FakeHttpContextBuilder();

            httpContextBuilder.Append(new ConfigureFakeIdentity(_currentUserName));

            _sut = new OrderItemsController(_mockRepo.Object, _mockLogger.Object, _mockMapper.Object);
            _sut.ApplyFakeHttpContext(httpContextBuilder);
        }
Пример #11
0
 public static void CreateOrderItemAsync_NullModel_ThrowsException(
     CallOffId callOffId,
     CatalogueItemId catalogueItemId,
     OrderItemsController controller)
 {
     Assert.ThrowsAsync <ArgumentNullException>(
         async() => await controller.CreateOrderItemAsync(callOffId, catalogueItemId, null));
 }
Пример #12
0
        public static async Task GetAsync_OrderItemDoesNotExist_ReturnsNotFound(
            CallOffId callOffId,
            CatalogueItemId catalogueItemId,
            OrderItemsController controller)
        {
            var response = await controller.GetAsync(callOffId, catalogueItemId);

            response.Result.Should().BeOfType <NotFoundResult>();
        }
Пример #13
0
        public static async Task ListAsync_InvalidCatalogueItemType_ReturnsNotFound(
            [Frozen] Mock <IOrderItemService> service,
            CallOffId callOffId,
            OrderItemsController controller)
        {
            service.Setup(o => o.GetOrderItems(callOffId, It.IsAny <CatalogueItemType>())).ReturnsAsync((List <OrderItem>)null);
            var response = await controller.ListAsync(callOffId, CatalogueItemType.AdditionalService);

            response.Result.Should().BeOfType <NotFoundResult>();
        }
Пример #14
0
        public static async Task CreateOrderItemAsync_OrderDoesNotExist_ReturnsNotFound(
            CallOffId callOffId,
            CatalogueItemId catalogueItemId,
            CreateOrderItemModel model,
            OrderItemsController controller)
        {
            var result = await controller.CreateOrderItemAsync(callOffId, catalogueItemId, model);

            result.Should().BeOfType <NotFoundResult>();
        }
        public void GetOrderItemReturns404WhenOrderNotFound()
        {
            _mockOrderItemAccess.Reset();
            _mockOrderItemAccess.Setup(a => a.GetOrderItem(It.IsAny <Guid>())).Returns((OrderItem)null);
            OrderItemsController sut = CreateSystemUnderTest();

            var result = sut.Get(It.IsAny <Guid>());

            _mockOrderItemAccess.Verify(a => a.GetOrderItem(It.IsAny <Guid>()), Times.Once);
            Assert.IsType <NotFoundResult>(result);
        }
        public void GetOrderItems_OkResult()
        {
            //Arrange
            var controller = new OrderItemsController(_uow);

            //Act
            var result = controller.Get();

            //Assert
            Assert.IsType <List <OrderItem> >(result.Value);
        }
        //private FormStates state;

        #endregion

        #region Constructor
        public PickingListForm(ProductController aProductController, CustomerController aCustomerController)
        {
            InitializeComponent();
            productController    = aProductController;
            customerController   = aCustomerController;
            orderItemsController = new OrderItemsController();
            orderController      = new OrderController();
            FillCombo();
            ItemsListView();
            HideAll(false);
        }
        public void DeleteOrderItem_OkResult()
        {
            //Arrange
            var controller = new OrderItemsController(_uow);

            //Act
            var result = controller.Delete(10);

            //Assert
            Assert.IsType <OkResult>(result.Result);
        }
        public void GetOrderItemById_NotFoundResult()
        {
            //Arrange
            var controller = new OrderItemsController(_uow);
            int orderId    = 3333333;

            //Act
            var result = controller.Get(orderId);

            //Assert
            Assert.IsType <NotFoundResult>(result.Result);
        }
        public void GetOrderItemById_OkResult()
        {
            //Arrange
            var controller  = new OrderItemsController(_uow);
            int orderItemId = 1;

            //Act
            var result = controller.Get(orderItemId);

            //Assert
            Assert.IsType <OrderItem>(result.Value);
        }
Пример #21
0
        public static async Task DeleteOrderItemAsync_OrderDoesNotExist_ReturnsNotFoundResult(
            [Frozen] Mock <IOrderItemService> service,
            [Frozen] CallOffId callOffId,
            OrderItemsController controller)
        {
            service.Setup(o => o.GetOrderWithCatalogueItems(callOffId))
            .ReturnsAsync((Order)null);

            var response = await controller.DeleteOrderItemAsync(callOffId, new CatalogueItemId(42, "111"));

            response.Should().BeOfType <NotFoundResult>();
        }
        public PoppelMDIParent()
        {
            InitializeComponent();
            this.WindowState     = FormWindowState.Maximized;
            orderItemsController = new OrderItemsController();
            employeeController   = new EmployeeController();
            customerController   = new CustomerController();
            productController    = new ProductController();
            orderController      = new OrderController();

            HideAll();
        }
 public OrderForm(CustomerController aCustomerController, Customer aCustomer)
 {
     InitializeComponent();
     customer             = aCustomer;
     customerController   = aCustomerController;
     orderItemsController = new OrderItemsController();
     productController    = new ProductController();
     orderController      = new OrderController();
     SetUp();
     FillCombo();
     ShowButtons(false);
     ItemsListView();
 }
Пример #24
0
        private void btnAcceptDefaultAddress_Click(object sender, EventArgs e)
        {
            string IDAddress_User = lstAddress[indexCombobox];
            bool   check          = OrderItemsController.ChangeDefauleAddress_User(UserName, PassWord, IDAddress_User, ref err);

            if (check == true)
            {
                MessageBox.Show("Bạn đã đổi địa chỉ mặc định thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Đổi địa chỉ mặc định thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void GetOrderItemReturnsOkayWhenOrderIsFound()
        {
            OrderItem orderItem = _fixture.Create <OrderItem>();

            _mockOrderItemAccess.Reset();
            _mockOrderItemAccess.Setup(a => a.GetOrderItem(It.IsAny <Guid>())).Returns(orderItem);
            OrderItemsController sut = CreateSystemUnderTest();

            var result = sut.Get(It.IsAny <Guid>());

            _mockOrderItemAccess.Verify(a => a.GetOrderItem(It.IsAny <Guid>()), Times.Once);
            Assert.IsType <OkObjectResult>(result);
            Assert.NotNull((OrderItem)((OkObjectResult)result).Value);
        }
Пример #26
0
        public async Task GivenFittingDate_WhenGetTotalBuysIsCalled_ThenReturnTotalPriceAsDecimal()
        {
            //Arrange
            _mockOrderIitemsService.Setup(x => x.GetTotalBuys(new DateTime(2018, 5, 12))).ReturnsAsync(It.IsAny <decimal>());
            var sut = new OrderItemsController(_mockOrderIitemsService.Object);

            //Act
            var result = await sut.GetTotalBuys(It.IsAny <DateTime>());

            //Assert
            Assert.AreEqual(It.IsAny <decimal>(), result);
            Assert.IsInstanceOf <decimal>(result);
            _mockOrderIitemsService.Verify(x => x.GetTotalBuys(It.IsAny <DateTime>()), Times.Exactly(1));
        }
        public async Task DeleteOrderItemReturnsOkayWhenOrderItemDeleted()
        {
            Guid orderItemId = Guid.NewGuid();

            _mockOrderItemAccess.Reset();
            _mockOrderItemAccess.Setup(a => a.RemoveOrderItemAsync(orderItemId, It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);

            OrderItemsController sut = CreateSystemUnderTest();

            var result = await sut.DeleteAsync(orderItemId, It.IsAny <CancellationToken>());

            _mockOrderItemAccess.Verify(a => a.RemoveOrderItemAsync(orderItemId, It.IsAny <CancellationToken>()), Times.Once);
            Assert.IsType <OkResult>(result);
        }
Пример #28
0
        private void dtGVShoppingCart_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            float  Quantity = float.Parse(this.dtGVShoppingCart.CurrentRow.Cells["colQuantity"].Value.ToString());
            string ItemName = this.dtGVShoppingCart.CurrentRow.Cells["colItemName"].Value.ToString();
            bool   check    = OrderItemsController.UpdateItem_Cart(UserName, PassWord, ItemName, Quantity, ref err);

            if (check == true)
            {
                MessageBox.Show("Bạn đã thay đổi số lượng món ăn " + ItemName + " là : " + Quantity, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Bạn đã thay đổi số lượng món ăn " + ItemName + " thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        public async Task DeleteOrderItemReturns404WhenOrderItmNotFound()
        {
            Guid orderItemId = Guid.NewGuid();

            _mockOrderItemAccess.Reset();
            _mockOrderItemAccess.Setup(a => a.RemoveOrderItemAsync(orderItemId, It.IsAny <CancellationToken>()))
            .ThrowsAsync(new OrderItemNotFoundException(string.Empty));

            OrderItemsController sut = CreateSystemUnderTest();

            var result = await sut.DeleteAsync(orderItemId, It.IsAny <CancellationToken>());

            _mockOrderItemAccess.Verify(a => a.RemoveOrderItemAsync(orderItemId, It.IsAny <CancellationToken>()), Times.Once);
            Assert.IsType <NotFoundResult>(result);
        }
Пример #30
0
        private void cbbDefalutAddress_Click(object sender, EventArgs e)
        {
            DataTable dtIDUser = OrderItemsController.IDUser_Find(UserName, PassWord).Tables[0];
            string    IDUser   = dtIDUser.Rows[0][0].ToString();

            cbbDefalutAddress.Items.Clear();
            DataTable dtAddress_User = OrderItemsController.All_Address_Show(IDUser, UserName, PassWord).Tables[0];

            foreach (DataRow dr in dtAddress_User.Rows)
            {
                string temp = dr["Street"].ToString() + ", " + dr["Ward"].ToString() + ", " + dr["District"].ToString() + ", " + dr["Province"].ToString();
                cbbDefalutAddress.Items.Add(temp);
                string IDAddress_User = dr["IDAddress_User"].ToString();
                lstAddress.Add(IDAddress_User);
            }
        }