Beispiel #1
0
        public ActionResult EditProduct([Bind(Include = "ProductID,SellerUsername,ProductName,Description,Price,StockQty,CategoryID")] Product product, HttpPostedFileBase file)
        {
            string prevImageLink = new ProductsBL().GetProductByID(product.ProductID).ImageLink;
            string filename      = "";

            if (file != null && file.ContentLength > 0)
            {
                string absolutePathOfImagesFolder = Server.MapPath("\\Images");
                filename = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName);
                file.SaveAs(absolutePathOfImagesFolder + "\\" + filename);
                product.ImageLink = ("\\Images\\" + filename).ToString();
            }
            else
            {
                product.ImageLink = prevImageLink;
            }
            product.SellerUsername = User.Identity.Name;
            if (ModelState.IsValid)
            {
                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CategoryID = new SelectList(db.ProductCategories, "CategoryID", "Name", product.CategoryID);
            ViewBag.Username   = new SelectList(db.Users, "Username", "Password", product.SellerUsername);
            return(View(product));
        }
Beispiel #2
0
 public string ValidateMaterialName(int intId, string strName)
 {
     try
     {
         ProductsBL        objMaterialBl = new ProductsBL();
         ApplicationResult objResult     = new ApplicationResult();
         objResult = objMaterialBl.Product_ValidateName(intId, strName);
         if (objResult != null)
         {
             if (objResult.resultDT.Rows.Count > 0)
             {
                 return("Not Available");
             }
             else
             {
                 return("Available");
             }
         }
         return("Try Again");
     }
     catch (Exception ex)
     {
         return(ex.ToString());
     }
 }
Beispiel #3
0
        public ActionResult Update(int productId)
        {
            //you must do a try catch in order to handle bad inserted data for example one must enter an integer and he enters a string
            Product productToEdit = new ProductsBL().GetProduct(productId);

            return(View(productToEdit));
        }
Beispiel #4
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         ProductsBL     productsBL = new ProductsBL();
         List <Product> products   = productsBL.GetProducts();
         GridViewProducts.DataSource = products;
         GridViewProducts.DataBind();
     }
 }
        public ActionResult EditDetails(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Product  p  = db.Products.Find(id);
            CartView cv = new ProductsBL().GetCartDetails(HttpContext.User.Identity.Name, p.ProductID);

            return(View(cv));
        }
Beispiel #6
0
        public ActionResult Products(string Category, string Search)
        {
            ProductsBL obj = new ProductsBL();
            var        lst = obj.GetProductList();

            obj = null;
            ProductLst model = new ProductLst();

            model.ProductViewModelLst = lst;
            return(View("ProudctListing", model));
        }
Beispiel #7
0
        public void DeletePermanently()
        {
            //Arrange
            ResetDataBase();
            ProductsBL productsBL = DI.Resolve <ProductsBL>();

            //Act
            productsBL.DeletePermanently(1);

            //Asserts
        }
        public ActionResult Index()
        {
            HomeViewModel           hvm = new HomeViewModel();
            List <ProductViewModel> productViewModelList = new List <ProductViewModel>();
            ProductsBL obj = new ProductsBL();
            var        lst = obj.GetProductList();

            obj = null;
            hvm.NewArrivalList = lst;
            return(View(hvm));
        }
Beispiel #9
0
        public void CalculatePriceInTheMainCurrency_WithMainCurrency()
        {
            //Arrange
            ResetDataBase();
            ProductsBL productsBL = DI.Resolve <ProductsBL>();

            //Act
            decimal actual = productsBL.CalculatePriceInTheMainCurrency(1, 100);

            //Assert
            Assert.That(actual, Is.EqualTo(100));
        }
Beispiel #10
0
        public void CalculatePriceInTheMainCurrency()
        {
            //Arrange
            ResetDataBase();
            ProductsBL productsBL = DI.Resolve <ProductsBL>();

            //Act
            decimal actual = productsBL.CalculatePriceInTheMainCurrency(3, 100, new DateTime(2016, 5, 5));

            //Assert
            Assert.That(actual, Is.EqualTo(2564));
        }
Beispiel #11
0
 public ProductsController(ProductCategoriesBL productCategoriesBL,
                           ProductsBL productsBL, BrandsBL brandsBL, CountriesBL countriesBL,
                           ContentContentTypesBL contentContentTypesBL, ProductPhotosBL productPhotosBL,
                           CurrenciesBL currenciesBL)
 {
     _productCategoriesBL   = productCategoriesBL;
     _productsBL            = productsBL;
     _brandsBL              = brandsBL;
     _countriesBL           = countriesBL;
     _contentContentTypesBL = contentContentTypesBL;
     _productPhotosBL       = productPhotosBL;
     _currenciesBL          = currenciesBL;
 }
 /// <summary>
 /// Applies a search and returns the search results.
 /// </summary>
 /// <returns></returns>
 public ActionResult Search(string search)
 {
     try
     {
         var results = ProductsBL.Search(search);
         return(Content(JsonConvert.SerializeObject(results)));
     }
     catch (Exception ex)
     {
         m_logger.Error(ex);
         throw;
     }
 }
Beispiel #13
0
        public void Delete_ShouldUnassignFromCtegories()
        {
            //Arrange
            ResetDataBase();
            ProductsBL productsBL = DI.Resolve <ProductsBL>();

            //Act
            productsBL.Delete(1);

            //Assert
            bool isDeleted = EntityFrameworkDbContext.Products.Where(product => product.Id == 1).Select(product => product.IsDeleted).Single();

            Assert.That(isDeleted, Is.True);
        }
Beispiel #14
0
        public ActionResult ProductCatalog(string input)//we have to call the method in the business logic layer
        {
            IQueryable <Product> foundProducts = new ProductsBL().GetProducts(input);
            List <Product>       listProduct   = new List <Product>();

            foreach (Product p in foundProducts)
            {
                if (p.Available == true)
                {
                    listProduct.Add(p);
                }
            }
            return(View(foundProducts)); //the returned list of users will he be displayed
                                         //in the same view tha was loaded in the first action
        }
Beispiel #15
0
        public ActionResult ProductCatalog()
        {
            IQueryable <Product> listProducts = new ProductsBL().GetProducts(); //i am storing the list of books
            List <Product>       listProduct  = new List <Product>();

            foreach (Product p in listProducts)
            {
                if (p.Available == true)
                {
                    listProduct.Add(p);
                }
            }

            return(View(listProduct));
        }
Beispiel #16
0
        public ActionResult ProductDetail(Guid Id, bool isAjaxReq)
        {
            ProductsBL obj = new ProductsBL();
            ProductDetailsViewModel model = obj.GetProductDetail(Id);

            //List<ColourModel> colourModel = obj.GetColourByStyleName(model.StyleName);
            //List<SizeModel> sizeModel = obj.GetSizeByStyleName(model.StyleName);
            obj = null;
            if (isAjaxReq == true)
            {
                string modelString = RenderRazorViewToString("_productDetail", model);
                return(Json(new { ModelString = modelString }, JsonRequestBehavior.AllowGet));
            }

            return(View(model));
        }
Beispiel #17
0
        public ActionResult Index(ProductModel data, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null && file.ContentLength > 0)
                {
                    string absolutePathOfImagesFolder = Server.MapPath("\\Images");
                    string filename = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName);
                    file.SaveAs(absolutePathOfImagesFolder + "\\" + filename);

                    ProductsBL pbl = new ProductsBL();
                    pbl.AddProduct(data.ProductName, HttpContext.User.Identity.Name, data.Description, data.Price, "\\Images\\" + filename, data.StockQty, data.CategoryID);
                    return(RedirectToAction("Index", "ViewSellerProduct")); //redirect to view products page
                }
            }
            return(View());
        }
Beispiel #18
0
        protected void gvProducts_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            ApplicationResult objResult = new ApplicationResult();

            ViewState["ID"] = e.CommandArgument;
            if (e.CommandName == "Edit1")
            {
                //BindProducts();
                objResult = new ProductsBL().Product_Select(Convert.ToInt16(ViewState["ID"].ToString()));
                DataTable objProductdt = new DataTable();
                if (objResult != null)
                {
                    objProductdt = objResult.resultDT;
                    if (objProductdt.Rows.Count > 0)
                    {
                        txtProductName.Text   = objProductdt.Rows[0]["ProductName"].ToString();
                        txtUnitName.Text      = objProductdt.Rows[0]["UnitName"].ToString();
                        txtProductName.Text   = objProductdt.Rows[0]["ProductName"].ToString();
                        txtSellingPrice.Text  = objProductdt.Rows[0]["SellingRate"].ToString();
                        txtPurchasePrice.Text = objProductdt.Rows[0]["PurchaseRate"].ToString();
                        txtDescription.Text   = objProductdt.Rows[0]["Description"].ToString();
                        if (objProductdt.Rows[0]["ImagePath"].ToString() != "")
                        {
                            imgCLogo.ImageUrl = objProductdt.Rows[0]["ImagePath"].ToString();
                            //byte[] bytes = (byte[])objProductdt.Rows[0]["ImagePath"];
                            //ViewState["Logo"] = bytes;
                            //string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
                            //imgCLogo.ImageUrl = "data:image/png;base64," + base64String;
                        }
                        ViewState["Mode"] = "Edit";
                        PanelVisibility(false, true);
                    }
                }
            }
            else if (e.CommandName == "Delete1")
            {
                objResult = new ProductsBL().Product_Delete(Convert.ToInt32(ViewState["ID"].ToString()), Convert.ToInt32(Session[ApplicationSession.USERID].ToString()), DateTime.UtcNow);
                if (objResult != null)
                {
                    ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", objResult.status == ApplicationResult.CommonStatusType.SUCCESS
                    ? "<script>alert('Record Deleted Successfully.');</script>"
                    : "<script>alert('Opps!Something went Wrong.Contact Your Administrator.');</script>");
                    BindGrid();
                }
            }
        }
Beispiel #19
0
 protected void btnUpdate_Click(object sender, EventArgs e)
 {
     try
     {
         Guid       CurrentProductID = new Guid(Convert.ToString(Session["CurrentProductID"]));
         ProductsBL productsBL       = new ProductsBL();
         Product    product          = productsBL.GetProductByProductID(CurrentProductID);
         product.ProductName = txtProductName.Text;
         product.UnitPrice   = Convert.ToDecimal(txtUnitPrice.Text);
         productsBL.UpdateProduct(product);
         Response.Redirect("~/Products.aspx");
     }
     catch (Exception ex)
     {
         Response.Write(ex.Message);
     }
 }
Beispiel #20
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         if (!Page.IsPostBack)
         {
             if (Session["CurrentProductID"] != null)
             {
                 Guid       CurrentProductID = new Guid(Convert.ToString(Session["CurrentProductID"]));
                 ProductsBL productsBL       = new ProductsBL();
                 Product    product          = productsBL.GetProductByProductID(CurrentProductID);
                 txtProductName.Text = product.ProductName;
                 txtUnitPrice.Text   = Convert.ToString(product.UnitPrice);
             }
         }
     }
     catch (Exception ex)
     {
         Response.Write(ex.Message);
     }
 }
Beispiel #21
0
        public void SetPublish()
        {
            //Arrange
            ResetDataBase();
            ProductCategoriesBL target     = DI.Resolve <ProductCategoriesBL>();
            ProductsBL          productsBl = DI.Resolve <ProductsBL>();

            //Act
            target.SetPublish(65, false);

            //Asserts
            Assert.That(!target.GetById(65).Publish);
            Assert.That(!productsBl.GetById(86).Publish);
            Assert.That(!productsBl.GetById(87).Publish);
            Assert.That(!productsBl.GetById(88).Publish);
            Assert.That(!productsBl.GetById(89).Publish);
            Assert.That(!productsBl.GetById(90).Publish);
            Assert.That(!productsBl.GetById(91).Publish);
            Assert.That(!productsBl.GetById(92).Publish);
            Assert.That(!productsBl.GetById(93).Publish);
            Assert.That(!productsBl.GetById(95).Publish);
        }
Beispiel #22
0
        private void BindGrid()
        {
            ApplicationResult objResult = new ApplicationResult(0);

            objResult = new ProductsBL().Product_SelectAll();
            DataTable objProductdt = new DataTable();

            if (objResult != null)
            {
                if (objResult.resultDT.Rows.Count > 0)
                {
                    objProductdt         = objResult.resultDT;
                    gvPrdouct.DataSource = objProductdt;
                    gvPrdouct.DataBind();
                    PanelVisibility(blDivGrid: true, blDivPanel: false);
                }
                else
                {
                    PanelVisibility(blDivGrid: false, blDivPanel: true);
                }
            }
        }
Beispiel #23
0
        //get by product id
        public ActionResult EditProduct(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Product product = db.Products.Find(id);

            if (product == null)
            {
                return(HttpNotFound());
            }
            List <SelectListItem>   categories = new List <SelectListItem>();
            IList <ProductCategory> category   = new ProductsBL().GetProductCategories().ToList();

            foreach (ProductCategory pc in category)
            {
                categories.Add(new SelectListItem {
                    Text = pc.CategoryName, Value = pc.CategoryID.ToString()
                });
            }
            ViewData["categoriesList"] = categories;
            return(View(product));
        }
        public async Task <ActionResult> AddToCart(int?color, Guid?productId, int qty)
        {
            var      objResponse = new ResponseObject();
            CartList cartList    = new CartList();

            if (productId != null)
            {
                ProductsBL objProduct = new ProductsBL();
                var        Product    = objProduct.GetProductDetail(productId);
                objProduct = null;

                if (Product != null)
                {
                    CartViewModel model = new CartViewModel();
                    model.ProductId = Product.Id;
                    model.SalePrice = Product.SalePrice;
                    string UserId = string.IsNullOrEmpty(Convert.ToString(User.Identity.Name)) ? string.Empty : User.Identity.Name;
                    var    user   = await UserManager.FindByNameAsync(UserId);

                    model.UserId = user.Id;
                    if (Session["sessionid"] == null)
                    {
                        Session["sessionid"] = Session.SessionID;
                    }
                    model.SessionId = Convert.ToString(Session["sessionid"]);
                    model.Qty       = qty;
                    CartBL obj = new CartBL();
                    Guid   Id  = obj.AddCart(model);
                    obj = null;

                    if (Id != null)
                    {
                        objResponse.IsSuccess   = "true";
                        objResponse.StrResponse = CommonFunction.SuccessMessage("Cart.", " Product added successfully.");
                        var list = this.RefreshList();
                        cartList.CartViewModelList = list;
                        cartList.Counter           = list.Count();
                    }

                    else
                    {
                        objResponse.IsSuccess   = "false";
                        objResponse.StrResponse = CommonFunction.ErrorMessage("Cart.", "Oops something went wrong.");
                    }
                }
                else
                {
                    objResponse.IsSuccess   = "false";
                    objResponse.StrResponse = CommonFunction.ErrorMessage("Cart.", "Product not found");
                }
            }
            else
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage));
                objResponse.IsSuccess   = "false";
                objResponse.StrResponse = CommonFunction.ErrorMessage(CommonMessagetype.TechnicalError.ToString(), CommonMessage.ErrorMessage);
            }
            return(Json(new
            {
                objResponse,
                html = this.RenderRazorViewToString("_miniCart", cartList),
            }, JsonRequestBehavior.AllowGet));
        }
        public string AddToCart(int pId, int quantity)
        {
            string value = new ProductsBL().AddToCart(HttpContext.User.Identity.Name, pId, quantity);

            return(value);
        }
        public ActionResult Index()
        {
            List <ProductsView> products = new ProductsBL().GetAllProducts().ToList();

            return(View(products));
        }
 /// <summary>
 /// Submits an order.
 /// </summary>
 /// <returns></returns>
 public ActionResult Submit(Order order)
 {
     ProductsBL.SubmitOrder(order);
     return(View(order));
 }
        // GET: Orders
        public ActionResult Index()
        {
            int workerId = UserStateManager.Instance.WorkerId;

            return(View(ProductsBL.GetOrders(workerId)));
        }
Beispiel #29
0
 public ProductDetailsNodeProvider()
 {
     _productCategoriesBL = DI.Resolve <ProductCategoriesBL>();
     _productsBL          = DI.Resolve <ProductsBL>();
 }
Beispiel #30
0
 public ProductsController(ProductsBL productsBL)
 {
     _productsBL = productsBL;
 }