//public ActionResult IndexFromBrand(int id) //{ // if (Request.IsAuthenticated) // { // ViewBag.PageTittle = "Products"; // ViewBag.Id = id; // ViewBag.Type = "cat"; // var brandName = BrandDal.GetById(id).BrandName; // var Product = ProductDal.GetByProducBrand(id); // ViewBag.breadCrum = "<a href='/Admin/Brand/index'>" + brandName + "</a> >> Products "; // return View("Index",Product); // } // else // { // return RedirectToAction("index", "home"); // } //} public ActionResult Create(string id) { var product = new ProductModel(); product.ProductPrice = new List<ProductPriceModel>(); //for(int i=0;i<5;i++) //{ // product.ProductPrice.Add(new ProductPriceModel()); //} product.brandList = BrandDal.GetAllBrand(); product.CategoryList = CategoryDal.GetAllCategory(); product.ColorList = ColorDal.GetAllColor().Where(m => m.id != 0).ToList(); product.LengthList = LengthDal.GetAlllength().Where(m => m.id != 0).ToList(); string name = ""; string type = ""; int Id = 0; if (id != null) { Id = Convert.ToInt32(id); } if (Request.QueryString["tId"] != null) { Id= Convert.ToInt32(Request.QueryString["tId"]); } if (Request.QueryString["type"] != null) { type= Convert.ToString(Request.QueryString["type"]); } ViewBag.RequestType = type; if (Request.IsAuthenticated) { ViewBag.PageTittle = "Add Product"; if (type == "cat") { name = CategoryDal.GetById(Id).name; ViewBag.breadCrum = "<a href='/Admin/Category/index'>Category</a> >> <a href='/Admin/Product/IndexFromCategory/" + Id + "'>" + name + "</a> >> Add Product"; product.CatId = Id; } else { //name = BrandDal.GetById(Id).BrandName; ViewBag.breadCrum = "<a href='/Admin/Brand/index'>Brand</a> >> <a href='/Admin/Product/IndexFromBrand/" + Id + "'>" + name + "</a> >> Add Product"; product.BrandId = Id; } product.SelectedColorList = new List<ColorModel>();//ColorDal.GetAllColorsByProductId(Id); product.SelectedLengthList = new List<LengthModel>();//LengthDal.GetAllLengthByProductId(Id); return View(product); } else { return RedirectToAction("index", "home"); } }
public static bool Create(ProductModel obj) { bool check = true; try { var context = new Ecommerce.DbEntity.ecommerceEntities(); var newProduct = new DbEntity.product(); newProduct.brandid = obj.BrandId; newProduct.catid = obj.CatId; newProduct.discription = obj.Discription; newProduct.image = obj.Image; newProduct.name = obj.Name; //newProduct.productCode = +obj.Name.Replace(" ", "-"); newProduct.keyWord = obj.KeyWord; newProduct.isHot = obj.Ishot; context.products.Add(newProduct); context.SaveChanges(); foreach (var x in obj.ColorList) { var productPricing = new ProductPriceModel(); productPricing.ProductId = newProduct.id; productPricing.lengthId = x.LengthId; productPricing.colorId = x.id; productPricing.ourpriceangola = x.ourpriceangola; productPricing.OurPriceDollar = x.OurPriceDollar; productPricing.OurPriceEuro = x.OurPriceEuro; productPricing.ourpriceghana = x.ourpriceghana; productPricing.ourpricenigeria = x.ourpricenigeria; productPricing.OurPricePound = x.OurPricePound; productPricing.priceangola = x.priceangola; productPricing.PriceDollar = x.PriceDollar; productPricing.PriceEuro = x.PriceEuro; productPricing.priceghana = x.priceghana; productPricing.pricenigeria = x.pricenigeria; productPricing.PricePound = x.PricePound; check = ProductPricingDal.Create(productPricing); } } catch (Exception ex) { check = false; } return check; }
public static CartModel AddItemTocart(int productPriceId, CartModel obj, string Currency, int? quantity, int? deliverId) { bool check = true; decimal total = 0; decimal MinFreeDeliverammount = 0; if (obj == null) { obj = new CartModel(); obj.Product = new List<ProductModel>(); } if (obj.Product == null) { obj.Product = new List<ProductModel>(); } if (quantity.HasValue) { for (int i = 0; i < obj.Product.Count; i++) { if (obj.Product[i].Price.Id == productPriceId) { obj.Product[i].Price.Quantity = Convert.ToInt32(quantity); check = false; } } } var context = new Ecommerce.DbEntity.ecommerceEntities(); var productPrice = new ProductPriceModel(); productPrice = ProductPricingDal.GetPriceByProductPriceId(productPriceId, Currency); var product = new ProductModel(); product = ProductDal.GetById(productPrice.ProductId); product.Price = productPrice; if (check) { if (quantity.HasValue) { product.Price.Quantity = Convert.ToInt32(quantity); } obj.Product.Add(product); } var deliveryCharges = new DeliveryModel(); if (deliverId > 0) { deliveryCharges = DeliveryDal.GetById(Convert.ToInt32(deliverId)); } else { if (obj.DelivierId == 0) { deliveryCharges = DeliveryDal.GetDefault(); } else { deliveryCharges = DeliveryDal.GetById(Convert.ToInt32(obj.DelivierId)); } } obj.DelivierDays = deliveryCharges.DeliveryDays; obj.DelivierId = deliveryCharges.id; if (Currency == "Dollar") { obj.DelivierCharges = (decimal)deliveryCharges.deliveryDoller; MinFreeDeliverammount = (decimal)deliveryCharges.freeDeliveryAmountDoller; } else if (Currency == "Pound") { obj.DelivierCharges = (decimal)deliveryCharges.deliveryPound; MinFreeDeliverammount = (decimal)deliveryCharges.freeDeliveryAmountPound; } else if (Currency == "Euro") { obj.DelivierCharges = (decimal)deliveryCharges.deliveryEuro; MinFreeDeliverammount = (decimal)deliveryCharges.freeDeliveryAmountEuro; } else if (Currency == "Naira") { obj.DelivierCharges = (decimal)deliveryCharges.deliveryNigria; MinFreeDeliverammount = (decimal)deliveryCharges.freeDeliveryAmountNigria; } else if (Currency == "Kwanza") { obj.DelivierCharges = (decimal)deliveryCharges.deliveryAngola; MinFreeDeliverammount = (decimal)deliveryCharges.freeDeliveryAmountAngola; } else if (Currency == "Cedi") { obj.DelivierCharges = (decimal)deliveryCharges.deliveryGhana; MinFreeDeliverammount = (decimal)deliveryCharges.freeDeliveryAmountGhana; } for (int i = 0; i < obj.Product.Count; i++) { decimal _total = Convert.ToDecimal(obj.Product[i].Price.Ourprice) * obj.Product[i].Price.Quantity; obj.Product[i].Price.TotalPrice = obj.Product[i].Price.Ourprice * obj.Product[i].Price.Quantity; total = total + _total; obj.Product[i].CountId = i; } obj.Difference = MinFreeDeliverammount - total; if (obj.Difference <= 0) { obj.Difference = 0; } obj.SubTotalTotal = total; obj.Total = total + obj.DelivierCharges; var validate = CoupanDal.ValidateCoupan(Convert.ToString(obj.DiscountCoupan)); if (validate != null) { obj.DiscountCoupan = obj.DiscountCoupan; obj.DiscountAmmount = (validate.DiscountPercentage / obj.SubTotalTotal) * 100; obj.Total = obj.Total - obj.DiscountAmmount; obj.Total = Math.Round(obj.Total, 2); obj.DiscountAmmount = Math.Round(obj.DiscountAmmount, 2); } obj.AllProductPrice=0; foreach (var x in obj.Product) { obj.AllProductPrice = obj.AllProductPrice + x.Price.TotalPrice; } return obj; }
public ActionResult Save(ProductModel obj) { bool check = true; var type=""; if (obj.Image == null) { obj.Image = ""; } var ColorlistObj= ColorDal.GetAllColor().Where(m => m.id != 0).ToList(); obj.LengthList = LengthDal.GetAlllength().Where(m => m.id != 0).ToList(); if (Request.IsAuthenticated) { string id = "0"; if (obj.Id > 0) { string path = ""; if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0) { path = Path.Combine(Server.MapPath("~/ProductImages/"), obj.Image); try { System.IO.File.Delete(path); } catch { // if there is exception in deleting the file } var file = Request.Files[0]; var _guid = Guid.NewGuid(); var _fileName = ""; var extention = Path.GetExtension(file.FileName); _fileName = _guid + extention; if (file != null && file.ContentLength > 0) { path = Path.Combine(Server.MapPath("~/ProductImages/"), _fileName); file.SaveAs(path); obj.Image = _fileName; } } obj.ColorList = new List<ColorModel>(); for (int i = 0; i < obj.LengthList.Count; i++) { for (int z = 0; z < ColorlistObj.Count; z++) { if (Request.Form["Chk-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id] != null) { if (Request.Form["Chk-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id].ToString().ToUpper() == "ON") { obj.ColorList.Add( new ColorModel { id = Convert.ToInt32(Request.Form["colorid-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), LengthId = Convert.ToInt32(Request.Form["LengthId-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), PriceDollar = Convert.ToDecimal(Request.Form["PriceDollar-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), PriceEuro = Convert.ToDecimal(Request.Form["PriceEuro-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), PricePound = Convert.ToDecimal(Request.Form["PricePound-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), pricenigeria = Convert.ToDecimal(Request.Form["pricenigeria-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), priceangola = Convert.ToDecimal(Request.Form["priceangola-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), priceghana = Convert.ToDecimal(Request.Form["priceghana-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), OurPriceDollar = Convert.ToDecimal(Request.Form["OurPriceDollar-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), OurPriceEuro = Convert.ToDecimal(Request.Form["OurPriceEuro-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), OurPricePound = Convert.ToDecimal(Request.Form["OurPricePound-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), ourpricenigeria = Convert.ToDecimal(Request.Form["ourpricenigeria-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), ourpriceangola = Convert.ToDecimal(Request.Form["ourpriceangola-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), ourpriceghana = Convert.ToDecimal(Request.Form["ourpriceghana-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), } ); } } } } check = ProductDal.Update(obj); if (check) { TempData["message"] = "Saved successfully"; } else { TempData["message"] = "Error while saving data"; } return RedirectToAction("Create", "Product", new { Id = obj.Id, type = type }); } else { if (Request.Files.Count > 0) { var file = Request.Files[0]; var _guid = Guid.NewGuid(); var _fileName = ""; //var fileName = Path.GetFileName(file.FileName); var extention = Path.GetExtension(file.FileName); _fileName = _guid + extention; if (file != null && file.ContentLength > 0) { var path = Path.Combine(Server.MapPath("~/ProductImages/"), _fileName); file.SaveAs(path); obj.Image = _fileName; } } obj.ColorList = new List<ColorModel>(); for (int i = 0; i < obj.LengthList.Count; i++) { for (int z = 0; z < ColorlistObj.Count; z++) { if (Request.Form["Chk-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id] != null) { if (Request.Form["Chk-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id].ToString().ToUpper() == "ON") { obj.ColorList.Add( new ColorModel { id = Convert.ToInt32(Request.Form["colorid-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), LengthId = Convert.ToInt32(Request.Form["LengthId-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), PriceDollar = Convert.ToDecimal(Request.Form["PriceDollar-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), PriceEuro = Convert.ToDecimal(Request.Form["PriceEuro-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), PricePound = Convert.ToDecimal(Request.Form["PricePound-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), pricenigeria = Convert.ToDecimal(Request.Form["pricenigeria-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), priceangola = Convert.ToDecimal(Request.Form["priceangola-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), priceghana = Convert.ToDecimal(Request.Form["priceghana-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), OurPriceDollar = Convert.ToDecimal(Request.Form["OurPriceDollar-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), OurPriceEuro = Convert.ToDecimal(Request.Form["OurPriceEuro-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), OurPricePound = Convert.ToDecimal(Request.Form["OurPricePound-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), ourpricenigeria = Convert.ToDecimal(Request.Form["ourpricenigeria-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), ourpriceangola = Convert.ToDecimal(Request.Form["ourpriceangola-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), ourpriceghana = Convert.ToDecimal(Request.Form["ourpriceghana-" + ColorlistObj[z].id + "-" + obj.LengthList[i].id]), } ); } } } } check = ProductDal.Create(obj); } type = Convert.ToString(Request.Form["RequestType"]); if (check) { TempData["message"] = "Saved successfully"; } else { TempData["message"] = "Error while saving data"; } //if (type == "cat") //{ // id = obj.CatId.ToString(); //} //else //{ // id = obj.BrandId.ToString(); //} return RedirectToAction("Create", "Product", new { Id = obj.CatId, type = type }); //return RedirectToAction("Create", "Product?tId="+id+"&type="+ type);//, new { Id = id, type = type } } else { return RedirectToAction("index", "home"); } }
public static bool Update(ProductModel obj) { bool check = true; try { var context = new Ecommerce.DbEntity.ecommerceEntities(); var Product = context.products.Where(m => m.id == obj.Id).FirstOrDefault(); Product.brandid = obj.BrandId; Product.catid = obj.CatId; Product.discription = obj.Discription; Product.image = obj.Image; Product.name = obj.Name; Product.keyWord = obj.KeyWord; Product.isHot = obj.Ishot; context.SaveChanges(); ProductPricingDal.Delete(obj.Id); foreach (var x in obj.ColorList) { var productPricing = new ProductPriceModel(); productPricing.ProductId = Product.id; productPricing.lengthId = x.LengthId; productPricing.colorId = x.id; productPricing.ourpriceangola = x.ourpriceangola; productPricing.OurPriceDollar = x.OurPriceDollar; productPricing.OurPriceEuro = x.OurPriceEuro; productPricing.ourpriceghana = x.ourpriceghana; productPricing.ourpricenigeria = x.ourpricenigeria; productPricing.OurPricePound = x.OurPricePound; productPricing.priceangola = x.priceangola; productPricing.PriceDollar = x.PriceDollar; productPricing.PriceEuro = x.PriceEuro; productPricing.priceghana = x.priceghana; productPricing.pricenigeria = x.pricenigeria; productPricing.PricePound = x.PricePound; check = ProductPricingDal.Create(productPricing); } } catch (Exception ex) { check = false; } return check; }
public static ProductModel GetByProductByProductId(int ProductId) { ProductModel Obj = new ProductModel(); var context = new Ecommerce.DbEntity.ecommerceEntities(); var product = context.products.Where(m => m.id == ProductId).FirstOrDefault(); Obj = new ProductModel { //Brand = BrandDal.GetById(Convert.ToInt32(x.brandid)).BrandName, Category = CategoryDal.GetById(Convert.ToInt32(product.catid)).name, Discription = product.discription, Image = string.IsNullOrEmpty(product.image) == false ? product.image : "NoImage.jpg", Name = product.name, Id = product.id, ProductPrice = ProductPricingDal.GetAllByProductId(product.id), SelectedColorList = ColorDal.GetAllColorsByProductId(product.id).Where(m => m.id > 0).ToList(), SelectedLengthList = LengthDal.GetAllLengthByProductId(product.id).Where(m => m.id > 0).ToList(), KeyWord = product.keyWord, CatId = Convert.ToInt32(product.catid), }; return Obj; }
public static ProductModel GetById(int id) { var context = new Ecommerce.DbEntity.ecommerceEntities(); var Product = context.products.Where(m => m.id == id).FirstOrDefault(); var Productobj = new ProductModel(); //Productobj.Brand = BrandDal.GetById(Convert.ToInt32(Product.brandid)).BrandName; Productobj.Category = CategoryDal.GetById(Convert.ToInt32(Product.catid)).name; Productobj.Discription = Product.discription; Productobj.Image = string.IsNullOrEmpty(Product.image) == false ? Product.image : "NoImage.jpg"; Productobj.Name = Product.name; Productobj.ProductPrice = ProductPricingDal.GetAllByProductId(Product.id); Productobj.Id = id; Productobj.CatId = Convert.ToInt32(Product.catid); Productobj.Ishot = Convert.ToBoolean(Product.isHot); Productobj.KeyWord = Product.keyWord; // Productobj.BrandId = Convert.ToInt32(Product.brandid); return Productobj; }
public ActionResult Ordersummery() { CartModel obj = new CartModel(); obj.Product = new List<ProductModel>(); var order = new OrderHeader(); order.OrderDetail = new List<OrderDetail>(); if (Session["OrderId"] != null) { order = OrderDal.GetByOrderId((int)Session["OrderId"]); } obj.Total = order.AmountInCurrencyChoosenByuser; obj.DelivierCharges = order.DeliveryCharges; foreach (var x in order.OrderDetail) { var productPrice = new ProductPriceModel(); productPrice = ProductPricingDal.GetPriceByProductPriceId(x.ProductPriceId, Convert.ToString(Session["currency"])); var product = new ProductModel(); product = ProductDal.GetById(productPrice.ProductId); var productModel = new ProductModel(); productModel.Image = product.Image; productModel.Name = product.Name; productModel.Price = new ProductPriceModel(); productModel.Price.Ourprice = x.ActualPriceInUserSeletedCurrency; productModel.Price.Quantity = x.Quantity; productModel.Price.LengthName = productPrice.LengthName; productModel.Price.ColorName = productPrice.ColorName; obj.Product.Add(productModel); } return PartialView(obj); }