示例#1
0
 public ActionResult Create([Bind(Include = "ID,Name,CategoryID,Price")] ProductModel product)
 {
     if (ModelState.IsValid)
     {
         try
         {
             // Checking if already exist a product with same name (case insensitive)
             if (productData.CheckIfAlreadyExist(product.Name) == false)
             {
                 IProductModel model = product;
                 productData.Create(model);
                 return(RedirectToAction("Index"));
             }
             else
             {
                 log.Info("The user tried to add a product that already existed");
                 return(View("AlreadyExists"));
             }
         }
         catch (Exception ex)
         {
             log.Error("Could't create a new product in the Database", ex);
             return(View("ErrorRetriveData"));
         }
     }
     else
     {
         log.Error("The model state of the product is invalid");
         return(View("WrongData"));
     }
 }
 public AddProductPresenter(IAddProductView view, IProductModel productModel)
     : base(view)
 {
     this.productModel      = productModel;
     view.AddButtonPressed += view_AddButtonPressed;
     view.CloseView        += view_CloseView;
 }
示例#3
0
        public int SaveItem(IProductModel item)
        {
            if (item.ID != 0)
            {
                var product = products.FirstOrDefault(x => x.ID == item.ID);
                product.IsChecked = item.IsChecked;

                var result = database.Update(product);
                if (result != 1)
                {
                    throw new SQLiteDatabaseLockedException();
                }
                return(product.ID);
            }
            else
            {
                var product = new ProductModel {
                    Name = item.Name, IsChecked = item.IsChecked
                };
                var result = database.Insert(product);
                products.Add(product);
                if (result != 1)
                {
                    throw new SQLiteDatabaseLockedException();
                }

                return(product.ID);
            }
        }
示例#4
0
        // Asks for confirmation in order to delete a product from the database
        public ActionResult Delete(int?id)
        {
            if (id != null)
            {
                try
                {
                    IProductModel product = productData.FindById((int)id);

                    if (product == null)
                    {
                        log.Error("Could't find a product in the Database - return null");
                        return(View("ErrorDelete"));
                    }

                    return(View(product));
                }

                catch (Exception ex)
                {
                    log.Error("Could't find a product in the Database", ex);
                    return(View("ErrorRetriveData"));
                }
            }
            else
            {
                log.Error("The product ID was null while trying to delete");
                return(View("ErrorDelete"));
            }
        }
示例#5
0
        public void ProductToSoldProduct_ShouldBeMapped()
        {
            IProductModel product = Factory.InstanceProductModel();

            product.Name          = "some product";
            product.Price         = 888.45M;
            product.CategoryID    = 654;
            product.Category.ID   = 654;
            product.Category.Name = "some category";

            int idTable = 36;

            Mock <IDataAccessSubCategory <ITableModel> > data = new Mock <IDataAccessSubCategory <ITableModel> >();

            data.Setup(x => x.FindById(idTable)).
            Returns(new TableModel()
            {
                ID = 36, AreaID = 7, NumberOfTable = 9765, Occupied = true, Area = new AreaModel {
                    ID = 7, Name = "some area"
                }
            });

            ISoldProductModel soldProduct = MappingObjects.ProductToSoldProduct(product, idTable, data.Object);

            Assert.Equal(product.Name, soldProduct.Name);
            Assert.Equal(product.Price, soldProduct.Price);
            Assert.Equal("", soldProduct.Detail);
            soldProduct.Category.Should().BeEquivalentTo(product.Category);
            soldProduct.Table.Should().BeEquivalentTo(data.Object.FindById(idTable));
        }
示例#6
0
 public void ChangeProductPrice(IProductModel productModel)
 {
     using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
     {
         cnn.Execute($"UPDATE Products SET Price = {productModel.Price} WHERE Id = {productModel.Id}");
     }
 }
示例#7
0
 public void ChangeQuantityOfProduct(IProductModel product, int quantityToAdd)
 {
     using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
     {
         cnn.Execute($"UPDATE Products SET Quantity = {quantityToAdd + product.Quantity} WHERE Id = {product.Id}");
     }
 }
示例#8
0
 public ActionResult Edit([Bind(Include = "ID,Name,CategoryID,Price")] ProductModel product)
 {
     if (ModelState.IsValid)
     {
         try
         {
             // Checking if already exist a product with same name that is not the one selected (case insensitive)
             if (productData.CheckIfAlreadyExist(product.Name) == false ||
                 productData.FindById(product.ID).Name == product.Name)
             {
                 IProductModel model = product;
                 productData.Update(model);
                 return(RedirectToAction("Index"));
             }
             else
             {
                 log.Info("The user tried to add a product that already existed");
                 return(View("AlreadyExists"));
             }
         }
         catch (Exception ex)
         {
             log.Error("Could't edit a product from Database", ex);
             return(View("ErrorRetriveData"));
         }
     }
     else
     {
         log.Error("The model state of the product is invalid");
         return(View("ErrorEdit"));
     }
 }
示例#9
0
        // Form to edit a product
        public ActionResult Edit(int?id)
        {
            if (id != null)
            {
                try
                {
                    IProductModel product = productData.FindById((int)id);
                    ViewBag.CategoryID = new SelectList(categoryData.GetAll(), "ID", "Name", product.CategoryID);

                    if (product == null)
                    {
                        log.Error("Could't find a product in the Database - return null");
                        return(View("ErrorEdit"));
                    }
                    return(View(product));
                }

                catch (Exception ex)
                {
                    log.Error("Could't find a product in the Database", ex);
                    return(View("ErrorRetriveData"));
                }
            }
            else
            {
                log.Error("The product ID was null while trying to edit");
                return(View("ErrorEdit"));
            }
        }
示例#10
0
 private void AddToCart(IProductModel product, int quantity)
 {
     product.Quantity = quantity;
     Cart.Add(product);
     Total = CartTotal();
     NotifyOfPropertyChange(() => Cart);
     NotifyOfPropertyChange(() => Total);
 }
示例#11
0
        public static void Example()
        {
            IUnityContainer container = new UnityContainer();

            container.RegisterType <IProductModel, CollectionProductModel>();
            container.RegisterType <IProductSerializer, JsonProductSerializer>();
            IProductModel productModel = container.Resolve <IProductModel>();

            Console.ReadKey();
        }
示例#12
0
        public void AddProdut(string prodName, int quanity)
        {
            IProductModel productmodel = Factorypattern.GetProduct();

            productmodel.Product   = _productRepository.Get(prodName);
            productmodel.Quanity   = quanity;
            productmodel.Promotion = _promotionRepository.GetAll().FirstOrDefault(p => p.Products.Contains(productmodel.Product));

            cart.Add(productmodel);
        }
示例#13
0
 // POST: api/Products
 public void Post([FromBody] ProductModel product)
 {
     if (ModelState.IsValid)
     {
         if (productData.CheckIfAlreadyExist(product.Name) == false)
         {
             IProductModel model = product;
             productData.Create(model);
         }
     }
 }
示例#14
0
 public IActionResult Add([FromServices] IProductModel productModel, string productId, PostDTO postDTO)
 {
     if (postDTO.Id <= 0 || productModel.GetDetailDTO(productId) == null)
     {
         return(BadRequest(new { message = "Add method is invalid, field 'ID' not require" }));
     }
     if (_postModel.AddDTO(postDTO) == null)
     {
         return(Problem(statusCode: 500, detail: "Can't add data"));
     }
     return(Ok());
 }
示例#15
0
        public void DeleteItem(IProductModel item)
        {
            var toRemove = products.FirstOrDefault(x => x.ID == item.ID);

            if (toRemove == null)
            {
                return;
            }

            products.Remove(toRemove);
            database.Delete(toRemove);
        }
示例#16
0
 // PUT: api/Products/5
 public void Put([FromBody] ProductModel product)
 {
     if (ModelState.IsValid)
     {
         if (productData.CheckIfAlreadyExist(product.Name) == false ||
             productData.FindById(product.ID).Name == product.Name)
         {
             IProductModel model = product;
             productData.Update(model);
         }
     }
 }
示例#17
0
        public DashboardAdminViewModel(IUserDBHelper userDBHelper, IProductDBHelper dataAccessModel, IProductModel productModel, IUserValidator userValidator)
        {
            _dataAccessModel    = dataAccessModel;
            _productModel       = productModel;
            _userDBHelper       = userDBHelper;
            _dashboardWelcomeVM = new DashboardWelcomeViewModel();
            _userValidator      = userValidator;

            DashboardWelcome();
            _dashboardWelcomeVM.ActivateProductsTab += _dashboardWelcomeVM_ActivateProductsTab;
            _dashboardWelcomeVM.ActivateUsersTab    += _dashboardWelcomeVM_ActivateUsersTab;
        }
示例#18
0
        /// <summary>
        /// It maps an object of type ProductModel to SoldProductModel
        /// </summary>
        public static ISoldProductModel ProductToSoldProduct(IProductModel product, int idTable, IDataAccessSubCategory <ITableModel> tableData)
        {
            ISoldProductModel soldProduct = Factory.InstanceSoldProductModel();

            soldProduct.Name          = product.Name;
            soldProduct.Price         = product.Price;
            soldProduct.CategoryID    = product.CategoryID;
            soldProduct.TableID       = idTable;
            soldProduct.Detail        = "";
            soldProduct.Category.ID   = product.CategoryID;
            soldProduct.Category.Name = product.Category.Name;
            soldProduct.Table         = tableData.FindById(idTable);

            return(soldProduct);
        }
        public ActionResult <FeedbackDTO> Add(
            [FromServices] ICacheHelper cache, [FromServices] IProductModel productModel,
            FeedbackDTO feedbackDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var re = _fbModel.AddDTO(feedbackDTO);

            if (re == null)
            {
                return(Problem(statusCode: 500, detail: "Can't add data"));
            }
            return(re);
        }
示例#20
0
文件: Class1.cs 项目: robmedlock/Net
        static void Main(string[] args)
        {
            IAbstractEcommerceFactory factory = new SqlServerEcommerceFactory();

            IAccountModel accountModel = factory.AccountModel;

            accountModel.Create(new Account());

            IProductModel productModel = factory.ProductModel;

            productModel.Create(new Product());

            IOrderModel orderModel = factory.OrderModel;

            orderModel.Create(new Order());
        }
示例#21
0
        public async System.Threading.Tasks.Task <IActionResult> AddAsync(
            [FromServices] IProductModel productModel,
            [FromServices] IPaymentService payment,
            [FromServices] UserManager <AppUser> userManager,
            [FromServices] ICacheHelper cache,
            OrderDTO orderDTO, int payId)
        {
            if (orderDTO.OrderItems == null || orderDTO.OrderItems == "" || payId <= 0)
            {
                return(BadRequest());
            }
            //Parse list order Item
            List <OrderDetailDTO> orderDetailDTOs = DataHelper.ParserJsonTo <List <OrderDetailDTO> >(orderDTO.OrderItems);

            if (orderDetailDTOs.Count < 0)
            {
                return(Problem(statusCode: 500, detail: "Data invalid"));
            }
            orderDTO.MethodPayId = payId;
            //Payment
            if (payId == 2)
            {
                var re = await payment.OnPayment((int)orderDTO.MethodPayId, orderDTO);

                if (re == false)
                {
                    return(Problem());
                }
            }
            if (User != null)
            {
                var email = User.FindFirst(ClaimTypes.NameIdentifier);

                orderDTO.UserId = email.Value;
            }
            var od = _orderModel.AddDTO(orderDTO, orderDetailDTOs);

            if (od == null)
            {
                Problem(statusCode: 500, detail: "Can't add data");
            }
            // productModel.UpdateForOrder(orderDetailDTOs);
            cache.DataUpdated(CacheKey.PRODUCT);
            return(Ok());
        }
示例#22
0
        public ActionResult TableAddProduct(int?idTable, int?idCategory, int?idProduct)
        {
            if (idProduct != null)
            {
                try
                {
                    // Finding the selected product and the table where is going to be added
                    ITableModel   table   = tableData.FindById((int)idTable);
                    IProductModel product = productData.FindById((int)idProduct);

                    if (product == null)
                    {
                        log.Error("Could't find a product in the Database - return null");
                        return(View("ErrorAddProduct"));
                    }

                    // Creates a SoldProductModel from a ProductModel that can be added to a list in each TableModel
                    ISoldProductModel soldProduct = MappingObjects.ProductToSoldProduct(product, (int)idTable, tableData);
                    soldProductData.Create(soldProduct);

                    // Sets the current table as opened (Occupied by products)
                    table.Occupied = true;
                    tableData.Update(table);
                    table.SoldProducts = soldProductData.GetByTable(table.ID);

                    // Joins list of products and selected table to a single model
                    mainPageModel.Products = productData.GetBySubGroup((int)idCategory).OrderBy(x => x.Name).ToList();;
                    mainPageModel.Tables.Add(table);
                }
                catch (Exception ex)
                {
                    log.Error("Could't load products, sold products or tables from Database", ex);
                    return(View("ErrorRetriveData"));
                }

                return(View(mainPageModel));
            }
            else
            {
                log.Error("The product ID was null while trying to access");
                return(View("ErrorAddProduct"));
            }
        }
示例#23
0
        public ActionResult <ImportProductDTO> Add([FromServices] IProductModel productModel, [FromServices] ICacheHelper cache, ImportProductDTO importProductDTO)
        {
            if (importProductDTO.ImportItems == null || importProductDTO.ImportItems == "")
            {
                return(BadRequest());
            }
            //Parse list order Item
            List <ImportDetailDTO> importDetailDTOs = DataHelper.ParserJsonTo <List <ImportDetailDTO> >(importProductDTO.ImportItems);

            //
            if (importDetailDTOs.Count == 0)
            {
                return(BadRequest(new { message = "Add method is invalid, field 'ID' not require" }));
            }
            var re = _importModel.AddDTO(importProductDTO, importDetailDTOs);

            if (re == null)
            {
                return(Problem(statusCode: 500, detail: "Can't add data"));
            }
            cache.DataUpdated(CacheKey.PRODUCT);
            return(re);
        }
        /// <summary>
        /// Initializes a new instance of the ManageProductsViewModel class.
        /// </summary>
        /// <param name="productModel"></param>
        public ManageProductsViewModel(IProductModel productModel)
        {
            this.productModel = productModel;
            if (IsInDesignMode)
            {
            #if DEBUG
                //this.UserProducts = new ObservableCollection<ProductViewModel>() {
                //    new ProductViewModel(new Product() { ID = 123, Name = "Domaine De La Seigneurie Des Tourelles Saumur 2008 750 mL bottle" }),
                //    new ProductViewModel(new Product() { ID = 124, Name = "Product 124" })
                //};

                //for (int i = 0; i < 20; i++)
                //{
                //    this.UserProducts.Add(new ProductViewModel(new Product() { ID = i, Name = "Product " + i }));
                //}

                this.SearchResults = new ObservableCollection<UserProductViewModel>() {
                    new UserProductViewModel(new UserProduct() { UsedByUser = false, Id = 123, Name = "Domaine De La Seigneurie Des Tourelles Saumur 2008 750 mL bottle" }),
                    new UserProductViewModel(new UserProduct() { UsedByUser = false, Id = 124, Name = "Product 124" })
                };

                for (int i = 0; i < 20; i++)
                {
                    this.SearchResults.Add(new UserProductViewModel(new UserProduct() { UsedByUser = i % 2 == 0, Id = i, Name = "Product " + i }));
                }
            #endif
            }
            else
            {
                this.SearchResults = new ObservableCollection<UserProductViewModel>();
                this.Refresh();
            }

            this.FindProductsCommand = new RelayCommand(() => this.FindProducts());
            this.AddProductCommand = new RelayCommand<UserProductViewModel>((product) => this.AddProduct(product));
            this.RemoveProductCommand = new RelayCommand<ProductViewModel>((product) => this.RemoveProduct(product));
        }
示例#25
0
 public ProductController(IProductModel productModel)
 {
     this.productModel = productModel;
 }
示例#26
0
 public void AddProductToCart(IProductModel product, int quantity)
 {
     product.Quantity = quantity;
     Cart.Add(product);
 }
示例#27
0
 static void Main(string[] args)
 {
     IProductModel productModel = Factory.ProductModel;
 }
 protected override void OnSetUp()
 {
     productModel = IoC.Resolve <IProductModel>();
 }
示例#29
0
 protected void Page_Load(object sender, EventArgs e)
 {
     order        = Session["order"] as Order;
     productModel = new EfProductModel();
 }
示例#30
0
 public ShoppingCartController(IShoppingCartModel shoppingCartModel, IProductModel productModel)
 {
     _shoppingCartModel = shoppingCartModel;
     _productModel      = productModel;
 }
示例#31
0
 public ValidateModel(IVariantModel variantModel, IProductModel productModel)
 {
     _productModel = productModel;
     _variantModel = variantModel;
 }