Ejemplo n.º 1
0
        public ActionResult AddProductRequest(String name, String code, String category, String price, String image, String desc)
        {
            ProductHandler prodHandler = new ProductHandler();
            ProductDto     product     = new ProductDto();

            product.Name = name;

            product.Code       = code;
            product.CategoryId = int.Parse(category);
            product.Price      = float.Parse(price);
            product.Image      = image;

            product.Description = System.Net.WebUtility.HtmlDecode(desc);
            prodHandler.AddNewProduct(product);

            if (Session[CONST.SESSION.USER] != null)
            {
                UserDto userDto = (UserDto)Session[CONST.SESSION.USER];
                if (UserHandler.AdminLogin(userDto.Username, userDto.Password) == CONST.ROLE.ADMIN)
                {
                    return(RedirectToAction("Index", "Admin"));
                }
                else if (UserHandler.AdminLogin(userDto.Username, userDto.Password) == CONST.ROLE.MOD)
                {
                    return(RedirectToAction("Index", "Mod"));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
        public static string CheckInsert(string name, string str_price, string str_quantity)
        {
            string response = "";

            if (name == "")
            {
                response = "Name must be filled!";
            }
            else if (str_price == "")
            {
                response = "Price must be filled!";
            }
            else
            {
                int price = int.Parse(str_price);
                int quantity;

                // TryParse bakal cobain parse argument pertama,
                // kalo berhasil dia bakal di masukin ke quarntyty
                if (int.TryParse(str_quantity, out quantity))
                {
                    ProductHandler.InsertNewProduct(name, price, quantity);
                }
                else
                {
                    ProductHandler.InsertNewProductWithDefaultQuantity(name, price);
                }
            }

            return(response);
        }
Ejemplo n.º 3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session[Constant.Keys.AUTH] != null)
     {
         User user = (User)Session[Constant.Keys.AUTH];
         if (user.RoleID == 2)
         {
             int     id = Int32.Parse(Request.QueryString["id"]);
             Product p  = ProductHandler.get(id);
             updateCartNameTxt.Text        = p.Name;
             updateCartPriceTxt.Text       = p.Price.ToString();
             updateCartStockTxt.Text       = p.Stock.ToString();
             updateCartProductTypeTxt.Text = ProductTypeHandler.getProductType(p.ProductTypeID);
         }
         else
         {
             var redirecTo = Constant.Routes.HOME_ROUTE;
             Response.Redirect(redirecTo);
         }
     }
     else
     {
         var redirecTo = Constant.Routes.HOME_ROUTE;
         Response.Redirect(redirecTo);
     }
 }
Ejemplo n.º 4
0
        public ActionResult EditPurchaseRequestDetail(PurchaseRequestDetailModel purchaseRequestDetail)
        {
            if (Session["UserLogon"] != null)
            {
                purchaseRequestDetail.Account = (AccountModel)Session["UserLogon"];
            }
            PurchaseRequestDetailResponse _purchaserequestdetailresponse = new PurchaseRequestDetailResponse();
            var purchaserequestdetailrequest = new PurchaseRequestDetailRequest
            {
                Data = purchaseRequestDetail
            };
            var requestnamabarang = new ProductRequest
            {
                Data = new ProductModel
                {
                    Id = Convert.ToInt32(purchaseRequestDetail.ProductId)
                }
            };

            ProductResponse namabarang = new ProductHandler(_unitOfWork).GetDetail(requestnamabarang);

            purchaserequestdetailrequest.Data.namabarang = purchaserequestdetailrequest.Data.namabarang != null ? purchaserequestdetailrequest.Data.namabarang : namabarang.Entity.Name;
            new PurchaseRequestDetailValidator(_unitOfWork).Validate(purchaserequestdetailrequest, out _purchaserequestdetailresponse);
            return(Json(new { data = _purchaserequestdetailresponse.Data }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> GetProductVariant([FromQuery] Guid productVariantId)
        {
            try
            {
                Guid temp = Guid.NewGuid();

                if (productVariantId != null)
                {
                    var response = await ProductHandler.GetProductByVariantId(productVariantId);

                    if (response != null)
                    {
                        //get product photos
                        var response2 = await ProductHandler.GetProductPhotosByProductVariantId(response.ProductVariantId);

                        response.ProductPhotos = response2;
                        return(Ok(response));
                    }
                }
                return(StatusCode(408, new ErrorResponse()
                {
                    Message = "Bad Request - Product Id is null"
                }));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                return(StatusCode(505, ex.Message));
            }
        }
        public ProductHttpController(IHostingEnvironment hostingEnvironment, InventoryDBContext context)
        {
            m_Handler = new ProductHandler(context, this);

            m_HostingEnvironment = hostingEnvironment;
            _context             = context;
        }
Ejemplo n.º 7
0
 public void AddingProductToCartFromWishListUser()
 {
     TestAction(() =>
     {
         string currentTestName = "AddingProductToCartFromWishListUser";
         log.Debug("Starting " + currentTestName + " Test;");
         log.Debug("For user " + user.FirstName + user.LastName + ";");
         HomePage home = new HomePage(driverForRun, false);
         SmallSleep();
         ProductHandler handler = new ProductHandler(driverForRun, home);
         Product product        = new Product(ProductCategories.Top_deals, 2, driverForRun);
         SmallSleep();
         int counter       = handler.GetContainerCounter(ProductContainer.Cart);
         int prodctsInCart = handler.CountProductsInContainer(ProductContainer.Cart, product);
         Assume.That(prodctsInCart <= 1, "Product already in cart, test will not proceed");
         MidSleep();
         handler.AddProductToContainer(ProductContainer.WishList, InterctionControlSet.Product_Title, product);
         Assert.That(handler.CountProductsInContainer(ProductContainer.WishList, product) == 1, "Product did not got to WishList");
         MidSleep();
         handler.AddProductToContainer(ProductContainer.Cart, InterctionControlSet.Container_Switch, product);
         MidSleep();
         handler.RemoveProductFromContainer(ProductContainer.WishList, InterctionControlSet.From_container, product);
         Assert.That((prodctsInCart + 1) == handler.CountProductsInContainer(ProductContainer.Cart, product), "Product wasn't added properly");
         Assert.That((counter + 1) == handler.GetContainerCounter(ProductContainer.Cart), "Conter wasn't updated properly");
     });
 }
Ejemplo n.º 8
0
        public ActionResult EditDeliveryOrderDetail(DeliveryOrderPusatDetailModel deliveryorderPusatDetail)
        {
            if (Session["UserLogon"] != null)
            {
                deliveryorderPusatDetail.Account = (AccountModel)Session["UserLogon"];
            }
            DeliveryOrderPusatDetailResponse _deliveryorderpusatdetailresponse = new DeliveryOrderPusatDetailResponse();
            var deliveryorderpusatdetailrequest = new DeliveryOrderPusatDetailRequest
            {
                Data = deliveryorderPusatDetail
            };
            var requestnamabarang = new ProductRequest
            {
                Data = new ProductModel
                {
                    Id = Convert.ToInt32(deliveryorderPusatDetail.ProductId)
                }
            };

            var requestnamavendor = new VendorRequest
            {
                Data = new VendorModel
                {
                    Id = deliveryorderPusatDetail.VendorId
                }
            };

            ProductResponse namabarang = new ProductHandler(_unitOfWork).GetDetail(requestnamabarang);
            VendorResponse  namavendor = new VendorHandler(_unitOfWork).GetDetail(requestnamavendor);

            deliveryorderpusatdetailrequest.Data.namabarang = deliveryorderpusatdetailrequest.Data.namabarang != null ? deliveryorderpusatdetailrequest.Data.namabarang : namabarang.Entity.Name;
            deliveryorderpusatdetailrequest.Data.namavendor = namavendor.Entity.namavendor;
            new DeliveryOrderPusatDetailValidator(_unitOfWork).Validate(deliveryorderpusatdetailrequest, out _deliveryorderpusatdetailresponse);
            return(Json(new { data = _deliveryorderpusatdetailresponse.Data }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 9
0
        public static IEnumerable <ViewProductModel> GetFiveProduct()
        {
            var rand = new Random();
            IEnumerable <ViewProductModel> p = ProductHandler.GetAllProduct().OrderBy(x => rand.Next()).Take(5);

            return(p);
        }
Ejemplo n.º 10
0
        public static Response UpdateProduct(int id, string name, int price, int stock, int productTypeId)
        {
            ProductType pt = ProductTypeHandler.GetProductTypeById(productTypeId);

            if (name == "")
            {
                return(new Response(false, "must be filled"));
            }
            else if (stock < 1)
            {
                return(new Response(false, "input must be 1 or more"));
            }
            else if (price < 1000)
            {
                return(new Response(false, "input must be above 1000"));
            }
            else if (price % 1000 != 0)
            {
                return(new Response(false, "input must be multiply of 1000"));
            }
            else if (pt == null)
            {
                return(new Response(false, "product type does not exist"));
            }
            else
            {
                ProductHandler.UpdateProduct(id, name, price, stock, productTypeId);
                return(new Response(true));
            }
        }
Ejemplo n.º 11
0
        public ActionResult GetProductList()
        {
            var _draw          = Request.Form.GetValues("draw").FirstOrDefault();
            var _start         = Request.Form.GetValues("start").FirstOrDefault();
            var _length        = Request.Form.GetValues("length").FirstOrDefault();
            var _sortColumn    = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
            var _sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();
            var _searchValue   = Request.Form.GetValues("search[value]").FirstOrDefault();

            int _pageSize = _length != null?Convert.ToInt32(_length) : 0;

            int _skip = _start != null?Convert.ToInt32(_start) : 0;



            var request = new ProductRequest
            {
                Draw               = _draw,
                SearchValue        = _searchValue,
                SortColumn         = _sortColumn,
                SortColumnDir      = _sortColumnDir,
                PageSize           = _pageSize,
                Skip               = _skip,
                IsForShowInFarmasi = true
            };

            request.Data = new Entities.MasterData.ProductModel();
            if (Session["UserLogon"] != null)
            {
                request.Data.Account = (AccountModel)Session["UserLogon"];
            }
            var response = new ProductHandler(_unitOfWork).GetListData(request);

            return(Json(new { data = response.Data, recordsFiltered = response.RecordsFiltered, recordsTotal = response.RecordsTotal, draw = response.Draw }, JsonRequestBehavior.AllowGet));
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["ShoppingCart"] != null)
        {
            Dictionary <int, int> shoppingCart = Session["ShoppingCart"] as Dictionary <int, int>;

            string         idString = string.Join(",", shoppingCart.Keys);
            ProductHandler ph       = new ProductHandler();
            List <Product> prodList = ph.GetProductsByIDs(idString);

            ShoppingCartHandler sch   = new ShoppingCartHandler();
            List <ShoppingCart> sList = sch.GetShoppingCartList(shoppingCart, prodList);



            Repeater1.DataSource = sList;
            Repeater1.DataBind();

            int total = 0;
            foreach (var item in sList)
            {
                total += item.Totalprice;
            }

            Label1.Text = $"NT${total.ToString()}";
        }
    }
Ejemplo n.º 13
0
        private void CreatBreadCrumbs(Product product)
        {
            try
            {
                ProductCategory    pc = ProductHandler.GetProductCategoryByProduct(product);
                HtmlGenericControl li = new HtmlGenericControl("li");
                HtmlGenericControl a  = new HtmlGenericControl("a");
                a.Attributes.Add("href", "/View/" + pc.ProductCatName);
                a.InnerText = pc.ProductCatName.ToUpper();
                li.Attributes.Add("class", "breadcrumb-item");
                li.Controls.Add(a);
                ProductBreadCrumbs.Controls.Add(li);

                ProductSubCategory ps  = ProductHandler.GetProductSubCategoryByProduct(product);
                HtmlGenericControl li2 = new HtmlGenericControl("li");
                HtmlGenericControl a2  = new HtmlGenericControl("a");
                a2.Attributes.Add("href", "/View/" + pc.ProductCatName + "/" + ps.ProductSubCatName);
                a2.InnerText = ps.ProductSubCatName.ToUpper();
                li2.Attributes.Add("class", "breadcrumb-item");
                li2.Controls.Add(a2);
                ProductBreadCrumbs.Controls.Add(li2);

                HtmlGenericControl li3 = new HtmlGenericControl("li");
                li3.InnerText = product.ProductName.ToUpper();
                li3.Attributes.Add("class", "breadcrumb-item-active");
                ProductBreadCrumbs.Controls.Add(li3);
            }
            catch (Exception e) {
                ProductBreadCrumbs.Controls.Clear();
                ProductBreadCrumbs.InnerText = "Error";
            }
        }
Ejemplo n.º 14
0
        public static Response UpdateProduct(int id, string name, string stock, string price)
        {
            if (name == "")
            {
                return(new Response(false, "Fill product name"));
            }
            if (stock == "" || stock.All(char.IsDigit) != true)
            {
                return(new Response(false, "Fill product stock"));
            }
            if (price == "" || price.All(char.IsDigit) != true)
            {
                return(new Response(false, "Fill product price"));
            }

            int _stock = Int32.Parse(stock);
            int _price = Int32.Parse(price);

            if (_stock < 1)
            {
                return(new Response(false, "Please input a minimum of 1 stock"));
            }
            if (_price < 1000 || _price % 1000 != 0)
            {
                return(new Response(false, "Please input the Price more than a thousand and divisble by a thousand"));
            }

            return(new Response(ProductHandler.UpdateProduct(id, name, _stock, _price), "Product has been updated"));
        }
Ejemplo n.º 15
0
        public void MovingProductFromCartToWishListUser()
        {
            TestAction(() =>
            {
                string currentTestName = "MovingProductFromCartToWishListUser";
                log.Debug("Starting " + currentTestName + " Test;");
                log.Debug("For user " + user.FirstName + user.LastName + ";");
                HomePage home = new HomePage(driverForRun, false);
                SmallSleep();
                ProductHandler handler = new ProductHandler(driverForRun, home);
                Product product        = new Product(ProductCategories.Top_deals, 2, driverForRun);
                SmallSleep();

                try
                {
                    int counterCart       = handler.GetContainerCounter(ProductContainer.Cart);
                    int prodctsInCart     = handler.CountProductsInContainer(ProductContainer.Cart, product);
                    int counterWishList   = handler.GetContainerCounter(ProductContainer.WishList);
                    int prodctsInWishList = handler.CountProductsInContainer(ProductContainer.WishList, product);
                    Assume.That(prodctsInCart >= 1, "Product not in cart, test will not proceed");
                    Assume.That(prodctsInWishList < 1, "Product already in wishist, test will not proceed");
                    MidSleep();
                    handler.AddProductToContainer(ProductContainer.WishList, InterctionControlSet.Container_Switch, product);
                    MidSleep();
                    Assert.That(handler.CountProductsInContainer(ProductContainer.WishList, product) == 1, "Product did not got to WishList");
                    Assert.That(handler.CountProductsInContainer(ProductContainer.Cart, product) == 0, "Product wasn't removed from cart properly");
                    Assert.That((counterCart - 1) == handler.GetContainerCounter(ProductContainer.Cart), "Cart Conter wasn't updated properly");
                    Assert.That((counterWishList + 1) == handler.GetContainerCounter(ProductContainer.WishList), "WishList Conter wasn't updated properly");
                }
                //clean-up
                finally { handler.RemoveProductFromContainer(ProductContainer.WishList, InterctionControlSet.From_container, product); }
            });
        }
Ejemplo n.º 16
0
        ////THis function show the product whose quantity is less 15
        public ActionResult FilterStock(string search, string toDate, string fromDate, int?categoryID, int?pageNo)
        {
            PurchaseStockViewModel model   = new PurchaseStockViewModel();
            ProductHandler         handler = new ProductHandler();

            model.SearchItem = search;
            model.toDate     = toDate;
            model.frmDate    = fromDate;

            model.CategoryId = categoryID.Value > 0 ? categoryID.Value : 0;

            pageNo = pageNo.HasValue ? pageNo.Value > 0 ? pageNo.Value : 1 : 1;
            //model.productList = handler.GetAllStockProduct(search,toDate,fromDate,pageNo.Value);

            var totalRecord = handler.GetAllStockProductCount(search, toDate, fromDate, categoryID.Value);

            model.productList = handler.GetAllStockProduct1(search, toDate, fromDate, categoryID.Value, pageNo.Value);

            if (model.productList != null)
            {
                model.Pager = new Pager(totalRecord, pageNo, 6);
                return(PartialView("_FilterStock", model));
            }

            return(PartialView("_FilterStock", model));
        }
Ejemplo n.º 17
0
 public void AddingProductToCartUser()
 {
     TestAction(() =>
     {
         string currentTestName = "AddingProductToCartUser";
         log.Debug("Starting " + currentTestName + " Test;");
         log.Debug("For user " + user.FirstName + user.LastName + ";");
         HomePage home     = new HomePage(driverForRun, false);
         SignInPage signin = new SignInPage(driverForRun);
         //bool isUserLogedIn = ValidateUser(user);
         Assume.That(signin.Login(user), "Failed login, test will not run");
         SmallSleep(); //moved from ValidateUser()
         var element = driverForRun.FindElement(By.XPath("//button[contains(@class,'d-md-block')]/div[text()=' START BROWSING ']"));
         TestHelper.JSexecutorClick(element, driverForRun);
         Assume.That(ValidateUser(user), "Logged-in account is not a user");
         SmallSleep();
         ProductHandler handler = new ProductHandler(driverForRun, home);
         Product product        = new Product(ProductCategories.Top_deals, 1, driverForRun);
         SmallSleep();
         int counter       = handler.GetContainerCounter(ProductContainer.Cart);
         int prodctsInCart = handler.CountProductsInContainer(ProductContainer.Cart, product);
         Assert.That(prodctsInCart < 1, "Selected product already in cart");
         MidSleep();
         handler.AddProductToContainer(ProductContainer.Cart, InterctionControlSet.Product_Details, product);
         MidSleep();
         Assert.That((prodctsInCart + 1) == handler.CountProductsInContainer(ProductContainer.Cart, product), "Product wasn't added properly");
         Assert.That((counter + 1) == handler.GetContainerCounter(ProductContainer.Cart), "Conter wasn't updated properly");
     });
 }
Ejemplo n.º 18
0
        public async Task <IActionResult> GetAllProducts()
        {
            try
            {
                List <Product> products = new List <Product>();
                var            response = await ProductHandler.GetAllProducts();

                if (response != null)
                {
                    //get product photos
                    for (int i = 0; i < response.Count; i++)
                    {
                        Product prod       = response[i];
                        var     prodPhotos = await ProductHandler.GetProductPhotosByProductId(prod.ProductId);

                        prod.ProductPhotos = prodPhotos;
                        products.Add(prod);
                    }
                    return(Ok(products));
                }
                return(null);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                return(StatusCode(505, ex.Message));
            }
        }
Ejemplo n.º 19
0
 public void WishlistSortingTest()
 {
     TestAction(() =>
     {
         string currentTestName = "WishlistSortingTest";
         log.Debug("Starting " + currentTestName + " Test;");
         log.Debug("For user " + user.FirstName + user.LastName + ";");
         HomePage home = new HomePage(driverForRun, false);
         //SignInPage signin = new SignInPage(driverForRun);
         //Assume.That(signin.Login(user), "Failed login, test will not run");
         //Assume.That(ValidateUser(user), "Logged-in account is not a user");
         SmallSleep();
         ProductHandler handler       = new ProductHandler(driverForRun, home);
         int[] selectedProductIndexes = new int[] { 1, 2, 3, 4, 5, 6, 7 };
         try
         {
             handler.BuildProductCollection(selectedProductIndexes, ProductCategories.Top_deals);
             handler.AddProdutRangeToContainer(selectedProductIndexes, ProductContainer.WishList, ProductCategories.Top_deals);
             handler.SortProducts(ProductContainer.WishList, SortingMethods.Brand);
             handler.ValidateProductSorting(SortingMethods.Brand);
             handler.SortProducts(ProductContainer.WishList, SortingMethods.Price, true);
             handler.ValidateProductSorting(SortingMethods.Price);
             handler.SortProducts(ProductContainer.WishList, SortingMethods.Rating);
             handler.ValidateProductSorting(SortingMethods.Rating);
         }
         finally
         {
             List <Product> cleanUpCollection = handler.GetCurrentProductsList(ProductContainer.WishList);
             foreach (var product in cleanUpCollection)
             {
                 handler.RemoveProductFromContainer(ProductContainer.WishList, InterctionControlSet.Product_Title, product);
             }
         }
     });
 }
Ejemplo n.º 20
0
        protected void addToCartButton_Click(object sender, EventArgs e)
        {
            int    id = Int32.Parse(Request.QueryString["id"]), Quantity = 0;
            string messageError = "";

            messageError = CartController.Add(addToCartQuantityTxt.Text, id);

            if (messageError != "")
            {
                labelErrorAddToCart.Text = messageError;
            }
            else
            {
                User user = (User)Session[Constant.Keys.AUTH];
                Quantity = int.Parse(addToCartQuantityTxt.Text);
                Product product = ProductHandler.get(id);
                if (CartHandler.get(user.ID, product.ID) != null)
                {
                    CartHandler.updateQuantity(user.ID, id, Quantity);
                }
                else
                {
                    CartInformation currentProduct = new CartInformation();
                    currentProduct.ID       = product.ID;
                    currentProduct.Name     = product.Name;
                    currentProduct.Price    = product.Price;
                    currentProduct.Quantity = Quantity;
                    currentProduct.SubTotal = currentProduct.Quantity * currentProduct.Price;
                    CartHandler.add(user.ID, id, Quantity);
                }
                var redirecTo = Constant.Routes.VIEW_CART_ROUTE;
                Response.Redirect(redirecTo);
            }
        }
Ejemplo n.º 21
0
        public static string Add(String Quantity, int ID)
        {
            string error           = "";
            int    QuantityProduct = 0;
            bool   flag            = true;

            try
            {
                QuantityProduct = int.Parse(Quantity);
            }
            catch (Exception ex)
            {
                if (ex != null)
                {
                    flag  = false;
                    error = "Input quantity must be a number";
                }
            }
            if (flag)
            {
                if (int.Parse(Quantity) <= 0)
                {
                    error = "Quantity must be more than 0";
                }
                else if (int.Parse(Quantity) > ProductHandler.getStock(ID))
                {
                    error = "Quantity must be less than or equals to current stock";
                }
                else if (int.Parse(Quantity) + CartHandler.getTotalQuantity(ID) > ProductHandler.getStock(ID))
                {
                    error = "The inputted quantity and the reserved quantity in other carts combined altogether must not exceed the selected product’s current stock";
                }
            }
            return(error);
        }
Ejemplo n.º 22
0
        public void Can_Updade_Product()
        {
            var entity = new Product("Product Name", 1.99M, 999);

            var moq = new Mock <IProductRepository>();

            moq.Setup(x => x.Update(It.IsAny <Product>()));
            moq.Setup(x => x.GetById(It.IsAny <int>())).Returns(entity);

            var handler = new ProductHandler(moq.Object);

            var result = handler
                         .Handle(new UpdateProductCommand()
            {
                Id = 0, Name = "Product Name", Price = 1.99M
            });

            result
            .Should()
            .BeNull();

            handler.Notifications
            .Should()
            .BeEmpty();

            moq.Verify(x => x.Update(It.IsAny <Product>()), Times.Once());
            moq.Verify(x => x.GetById(It.IsAny <int>()), Times.Once());
        }
        /// <summary>
        /// Executes the plug-in.
        /// </summary>
        /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
        /// <see cref="IPluginExecutionContext"/>,
        /// <see cref="IOrganizationService"/>
        /// and <see cref="ITracingService"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
        /// The plug-in's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the plug-in. Also, multiple system threads
        /// could execute the plug-in at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in plug-ins.
        /// </remarks>
        protected void ExecutePostVehicleandItemCatalogCreate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService    service = localContext.OrganizationService;
            ITracingService         trace   = localContext.TracingService;
            Entity product = (Entity)context.InputParameters["Target"];

            string message = context.MessageName;
            string error   = "";

            try
            {
                ProductHandler productHandler = new ProductHandler(service, trace);

                productHandler.ReplicateModelDescriptionName(product);
                productHandler.PopulateTaxRate(product);
            }
            catch (Exception ex)
            {
                //throw new InvalidPluginExecutionException(String.Concat("(Exception)\n", ex.Message, Environment.NewLine, ex.StackTrace, Environment.NewLine, error));
                throw new InvalidPluginExecutionException(ex.Message);
            }
        }
Ejemplo n.º 24
0
        protected void updateCartButton_Click(object sender, EventArgs e)
        {
            User   user = (User)Session[Constant.Keys.AUTH];
            int    id = Int32.Parse(Request.QueryString["id"]), Quantity = 0;
            string messageError = "";

            messageError = CartController.update(updateCartQuantityTxt.Text, id, user.ID);

            if (messageError != "")
            {
                labelErrorUpdateCart.Text = messageError;
            }
            else
            {
                Quantity = int.Parse(updateCartQuantityTxt.Text);
                Product product = ProductHandler.get(id);
                if (Quantity == 0)
                {
                    CartHandler.remove(user.ID, id);
                }
                else
                {
                    CartHandler.updateNewQuantity(user.ID, id, Quantity);
                }
                var redirecTo = Constant.Routes.VIEW_CART_ROUTE;
                Response.Redirect(redirecTo);
            }
        }
Ejemplo n.º 25
0
        // BUTTON EVENT FIRES
        protected void update_button_Click(object sender, EventArgs e)
        {
            notificationSuccess_label.Text = "";
            notificationError_label.Text   = "";
            if (inputUserWatchQuantity_textBox.Text != "" && inputUserWatchPrice_textBox.Text != "" && inputWatchName_textBox.Text != "")
            {
                if (upload.HasFile)
                {
                    Product p = ProductHandler.GetById(ProductId);
                    if (System.IO.File.Exists(Server.MapPath("~/") + p.ProductImage))
                    {
                        System.IO.File.Delete(Server.MapPath("~/") + p.ProductImage);
                    }

                    string image = getImageUploaded();

                    ProductHandler.UpdateWithImage(ProductId, inputWatchName_textBox.Text, image, Convert.ToDecimal(inputUserWatchPrice_textBox.Text), Int32.Parse(inputUserWatchQuantity_textBox.Text));
                }
                else
                {
                    ProductHandler.UpdateWithoutImage(ProductId, inputWatchName_textBox.Text, Convert.ToDecimal(inputUserWatchPrice_textBox.Text), Int32.Parse(inputUserWatchQuantity_textBox.Text));
                }

                notificationSuccess_label.Text = "Update Watch successfuly!";
                notificationError_label.Text  += "";

                Response.Redirect("Home.aspx");
            }
            else
            {
                checkEmptiness();
            }
        }
Ejemplo n.º 26
0
        public void ProductHandler_TryBuy_ThrowsIfInsufficientFunds()
        {
            var mockIVendingMachineOperations = new Mock <IVendingMachineOperations>();
            var productHandler = new ProductHandler(mockIVendingMachineOperations.Object);

            var productNames = new List <string>();

            productNames.Add("cola");
            productNames.Add("candy");
            productNames.Add("chips");

            var exceptionMessage = "";

            //try to buy each product with insufficient funds
            foreach (var product in productNames)
            {
                try
                {
                    productHandler.TryBuy(product, Constants.GetProductPrice(product) - 1);
                }
                catch (InsufficientCreditException ex)
                {
                    exceptionMessage = ex.Message;
                }

                Assert.AreEqual("Insufficient funds", exceptionMessage);
                exceptionMessage = "";
            }
        }
Ejemplo n.º 27
0
 public MainWindow()
 {
     InitializeComponent();
     myNavigationFrame = myFrame;
     productHandler    = new ProductHandler();
     myNavigationFrame.NavigationService.Navigate(new MainPage());
 }
Ejemplo n.º 28
0
        public static Response InsertProduct(int productTypeID, string name, string priceTxt, string stockTxt)
        {
            if (priceTxt == "")
            {
                return(new Response(false, "Price must be filled."));
            }

            if (name == "")
            {
                return(new Response(false, "Name must be filled."));
            }
            if (stockTxt == "")
            {
                return(new Response(false, "Stock must be filled."));
            }

            int stock = int.Parse(stockTxt);
            int price = int.Parse(priceTxt);

            if (stock < 1)
            {
                return(new Response(false, "Stock must be 1 or more"));
            }

            if (price < 1000 || price % 1000 != 0)
            {
                return(new Response(false, "Price must be over 1000 and multiply of 1000"));
            }

            Response response = ProductHandler.InsertProduct(productTypeID, name, price, stock);

            return(response);
        }
Ejemplo n.º 29
0
        public static Response UpdateProduct(int productid, string name, string priceTxt, string stockTxt)
        {
            if (priceTxt == "")
            {
                return(new Response(false, "Price must be filled."));
            }
            if (stockTxt == "")
            {
                return(new Response(false, "Stock must be filled."));
            }
            if (name == "")
            {
                return(new Response(false, "Name must be filled."));
            }

            int stock = int.Parse(stockTxt);
            int price = int.Parse(priceTxt);

            if (stock < 1)
            {
                return(new Response(false, "Stock must be 1 or over 1."));
            }

            if (price < 1000 || price % 1000 != 0)
            {
                return(new Response(false, "price must be above 1000 and multiply of 1000."));
            }

            Response response = ProductHandler.UpdateProduct(productid, name, price, stock);

            return(response);
        }
Ejemplo n.º 30
0
 private void SetLabelText(int productId)
 {
     Product p = ProductHandler.GetProduct(productId);
     prodName.Text = p.Name;
     prodPrice.Text = p.Price.ToString();
     ProdStock.Text = p.Stock.ToString();
 }
Ejemplo n.º 31
0
 static void Main(string[] args)
 {
     ProductHandler productHandler = new ProductHandler();
     var allProducts = productHandler.GetAll();
     foreach (var productDomain in allProducts)
     {
         Display(productDomain);
     }
 }