示例#1
0
        public void AddToCart(PRODUCT productdtls, int qty,string CouponCode)
        {
            // Get the matching cart and album instances
            var cartItem = storeDB.ProductCarts.SingleOrDefault(
                c => c.CartId == ShoppingCartId
                && c.PDT_Id == productdtls.Pid);
            var userToUpdate = storeDB.PRODUCTs.SingleOrDefault(u => u.Pid == productdtls.Pid);
            if (userToUpdate != null)
            {
                userToUpdate.PDT_offer = 0;
                userToUpdate.PDT_Discount_price = storeDB.PRODUCTs.SingleOrDefault(u => u.Pid == productdtls.Pid).PDT_Price;
                // userToUpdate.Mod_user_id = WebSecurity.CurrentUserId;
                userToUpdate.Mod_Datetime = System.DateTime.Now;

            }
            //To update offer value
            if (string.IsNullOrEmpty(CouponCode))
            {
                var offer = storeDB.Sp_GetOffer();
                var productoffer = from o in storeDB.ProductOfferValues
                                   where o.Pid == productdtls.Pid
                                   select o;

                foreach (var ofritem in productoffer)
                {
                    var updPDT = storeDB.PRODUCTs.SingleOrDefault(u => u.Pid == productdtls.Pid);
                    if (userToUpdate != null)
                    {
                        updPDT.PDT_offer = Convert.ToDecimal(ofritem.offer);
                        updPDT.offer_value_type_id = Convert.ToInt16(ofritem.OfrValtype);
                        updPDT.PDT_Discount_price = ofritem.OfrValtype == 1 ? (productdtls.PDT_Price - (ofritem.offer * productdtls.PDT_Price) / 100) : productdtls.PDT_Price - ofritem.offer;
                        // userToUpdate.Mod_user_id = WebSecurity.CurrentUserId;
                        updPDT.Mod_Datetime = System.DateTime.Now;

                    }

                }
            }
                 //To update Coupon Code value
            if (!string.IsNullOrEmpty(CouponCode))
            {
                var cupn = storeDB.Sp_GetCoupon(CouponCode);
                var productcupn = from o in storeDB.ProductCouponValues
                                   where o.Pid == productdtls.Pid
                                   select o;

                foreach (var cupnitem in productcupn)
                {
                    var updPDT = storeDB.PRODUCTs.SingleOrDefault(u => u.Pid == productdtls.Pid);
                    if (userToUpdate != null)
                    {
                        updPDT.PDT_offer = Convert.ToDecimal(cupnitem.offer);
                        updPDT.offer_value_type_id = Convert.ToInt16(cupnitem.offervaltype);
                        updPDT.PDT_Discount_price = cupnitem.offervaltype == 1 ? (productdtls.PDT_Price - (cupnitem.offer * productdtls.PDT_Price) / 100) : productdtls.PDT_Price - cupnitem.offer;
                        // userToUpdate.Mod_user_id = WebSecurity.CurrentUserId;
                        updPDT.Mod_Datetime = System.DateTime.Now;

                    }

                }
            }

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new ProductCart
                {
                    PDT_Id = productdtls.Pid,
                    CartId = ShoppingCartId,
                    Count = qty,
                    DateCreated = DateTime.Now
                };
                storeDB.ProductCarts.Add(cartItem);
            }
            else
            {
                // If the item does exist in the cart,
                // then add one to the quantity
                cartItem.Count++;
            }
            // Save changes
            storeDB.SaveChanges();
        }
示例#2
0
        public ActionResult Create(ProductInsert product)
        {
            //Check server side validation using data annotation
              //  var errors = ModelState
              //.Where(x => x.Value.Errors.Count > 0)
              //.Select(x => new { x.Key, x.Value.Errors })
              //.ToArray();
            if (ModelState.IsValid)
            {

                try
                {

                    // Insert Product
                    PRODUCT objnewproduct = new PRODUCT();
                    objnewproduct.Pid = (db.PRODUCTs.Max(i => (int?)i.Pid) ?? 0)+1;  //Convert.ToInt32(db.PRODUCTs.Max(x => x.Pid)) + 1;
                    objnewproduct.PDT_CODE = product.Product_Code;
                    objnewproduct.PDT_Name = product.Product_Name;
                    objnewproduct.PDT_Description = product.Product_Description;
                    objnewproduct.PDT_Price = product.Product_Price;
                    objnewproduct.Category_id = product.Category_id;
                    objnewproduct.Sub_Category_id =Convert.ToInt32(product.Sub_Category_id);
                    objnewproduct.offer_value_type_id = 1;// product.offer_id;
                    objnewproduct.Brand_id = Convert.ToInt32(product.brand_id);
                    objnewproduct.Add_user_Id = WebSecurity.CurrentUserId;
                    objnewproduct.Mod_user_id =  WebSecurity.CurrentUserId;
                    objnewproduct.Add_Datetime = System.DateTime.Now;
                    objnewproduct.Mod_Datetime = System.DateTime.Now;
                    objnewproduct.IsActive = true;
                    objnewproduct.PDT_offer = 1;// product.Product_offer;
                    objnewproduct.PDT_Discount_price = 1;// product.offer_id == 1 ? (product.Product_Price - (product.Product_offer * product.Product_Price) / 100) : product.Product_Price - product.Product_offer;
                    db.PRODUCTs.Add(objnewproduct);
                    db.SaveChanges();

                    int productid = db.PRODUCTs.Where(x => x.PDT_CODE == product.Product_Code).FirstOrDefault().Pid;
                    //insert PDT_IMAGE_PATH
                    // save image in folder
                   //image1
                    bool Firstflag = false;
                    bool sideflag = false;
                    bool vertiflag = false;
                    bool horiflag = false;
                    if (product.Firstflag == 1)
                    {
                        Firstflag = true;
                    }
                    if (product.Firstflag == 2)
                    {
                        sideflag = true;
                    }
                    if (product.Firstflag == 3)
                    {
                        horiflag = true;
                    }
                    if (product.Firstflag == 4)
                    {
                        vertiflag = true;
                    }
                    string ImageName = System.IO.Path.GetFileName(product.Imagepath.FileName);
                    string physicalPath = Server.MapPath(ConfigurationManager.AppSettings["ORIGINALPATH"] + ImageName);
                    product.Imagepath.SaveAs(physicalPath);
                    string targetPath = Server.MapPath(ConfigurationManager.AppSettings["RESZEFILEPATH"] + ImageName);
                    product.Imagepath.SaveAs(targetPath);
                    PDT_IMAGE_PATH objImages = new PDT_IMAGE_PATH();
                    objImages.img_id = (db.PDT_IMAGE_PATH.Max(i => (int?)i.img_id) ?? 0) + 1;
                    objImages.PDT_ID = productid;
                    objImages.Image_Path = ImageName;
                    objImages.Home_Flag = product.Homeflag;
                    objImages.First_Flag = Firstflag;
                    objImages.Img_type = "F";
                    objImages.User_id = WebSecurity.CurrentUserId;
                    objImages.His_Datetime = System.DateTime.Now;
                    db.PDT_IMAGE_PATH.Add(objImages);

                    //sideimage
                    if (product.sideImagepath != null)
                    {
                        ImageName = System.IO.Path.GetFileName(product.sideImagepath.FileName);
                        physicalPath = Server.MapPath(ConfigurationManager.AppSettings["ORIGINALPATH"] + ImageName);
                        product.sideImagepath.SaveAs(physicalPath);
                        targetPath = Server.MapPath(ConfigurationManager.AppSettings["RESZEFILEPATH"] + ImageName);
                        product.sideImagepath.SaveAs(targetPath);
                        PDT_IMAGE_PATH objsideImages = new PDT_IMAGE_PATH();
                        objsideImages.img_id = (db.PDT_IMAGE_PATH.Max(i => (int?)i.img_id) ?? 0) + 1;
                        objsideImages.PDT_ID = productid;
                        objsideImages.Image_Path = ImageName;
                        objsideImages.First_Flag = sideflag;
                        objsideImages.Img_type = "S";
                        objsideImages.User_id = WebSecurity.CurrentUserId;
                        objsideImages.His_Datetime = System.DateTime.Now;
                        db.PDT_IMAGE_PATH.Add(objsideImages);
                    }

                    //Horizontal image
                    if (product.horizontalImagepath != null)
                    {
                        ImageName = System.IO.Path.GetFileName(product.horizontalImagepath.FileName);
                        physicalPath = Server.MapPath(ConfigurationManager.AppSettings["ORIGINALPATH"] + ImageName);
                        product.horizontalImagepath.SaveAs(physicalPath);
                        targetPath = Server.MapPath(ConfigurationManager.AppSettings["RESZEFILEPATH"] + ImageName);
                        product.horizontalImagepath.SaveAs(targetPath);
                        PDT_IMAGE_PATH objhorzImages = new PDT_IMAGE_PATH();
                        objhorzImages.img_id = (db.PDT_IMAGE_PATH.Max(i => (int?)i.img_id) ?? 0) + 1;
                        objhorzImages.PDT_ID = productid;
                        objhorzImages.Image_Path = ImageName;
                        objhorzImages.User_id = WebSecurity.CurrentUserId;
                        objhorzImages.His_Datetime = System.DateTime.Now;
                        objhorzImages.First_Flag = horiflag;
                        objhorzImages.Img_type = "H";
                        db.PDT_IMAGE_PATH.Add(objhorzImages);
                    }
                    //vertical image
                    if (product.verticalImagepath != null)
                    {
                        ImageName = System.IO.Path.GetFileName(product.verticalImagepath.FileName);
                        physicalPath = Server.MapPath(ConfigurationManager.AppSettings["ORIGINALPATH"] + ImageName);
                        product.verticalImagepath.SaveAs(physicalPath);
                        targetPath = Server.MapPath(ConfigurationManager.AppSettings["RESZEFILEPATH"] + ImageName);
                        product.verticalImagepath.SaveAs(targetPath);
                        PDT_IMAGE_PATH objvertImages = new PDT_IMAGE_PATH();
                        objvertImages.img_id = (db.PDT_IMAGE_PATH.Max(i => (int?)i.img_id) ?? 0) + 1;
                        objvertImages.PDT_ID = productid;
                        objvertImages.Image_Path = ImageName;
                        objvertImages.User_id = WebSecurity.CurrentUserId;
                        objvertImages.His_Datetime = System.DateTime.Now;
                        objvertImages.First_Flag = vertiflag;
                        objvertImages.Img_type = "V";
                        db.PDT_IMAGE_PATH.Add(objvertImages);
                    }
                    //banner Image
                    if (product.BannerImagepath != null)
                    {
                        ImageName = System.IO.Path.GetFileName(product.BannerImagepath.FileName);
                        physicalPath = Server.MapPath(ConfigurationManager.AppSettings["ORIGINALPATH"] + ImageName);
                        product.BannerImagepath.SaveAs(physicalPath);
                        targetPath = Server.MapPath(ConfigurationManager.AppSettings["RESZEFILEPATH"] + ImageName);
                        product.BannerImagepath.SaveAs(targetPath);
                        PDT_IMAGE_PATH objBannerImages = new PDT_IMAGE_PATH();
                        objBannerImages.img_id = (db.PDT_IMAGE_PATH.Max(i => (int?)i.img_id) ?? 0) + 1;
                        objBannerImages.PDT_ID = productid;
                        objBannerImages.Image_Path = ImageName;
                        objBannerImages.User_id = WebSecurity.CurrentUserId;
                        objBannerImages.Img_type = "B";
                        objBannerImages.His_Datetime = System.DateTime.Now;
                        objBannerImages.Banner_Flag = true;
                        db.PDT_IMAGE_PATH.Add(objBannerImages);
                    }

                    db.SaveChanges();

                    //Specifications
                    foreach (var p in product.GetType().GetProperties())
                    {
                        // Console.WriteLine("Property {0} type {1} value {2}", p.Name, p.GetValue(obj, null).GetType().Name, p.GetValue(product, null));

                        if (db.KEY_Specifications.Any(u => u.spec_col_Name == p.Name))
                        {
                            var propvalue = p.GetValue(product, null);
                            if (propvalue != null)
                            {
                            Value_Specification objvaluespec = new Value_Specification();
                            objvaluespec.Spec_value_id = (db.Value_Specification.Max(i => (int?)i.Spec_value_id) ?? 0) + 1;
                            objvaluespec.Product_id = productid;
                            objvaluespec.Key_spec_id = db.KEY_Specifications.Where(x => x.spec_col_Name == p.Name).FirstOrDefault().spec_col_id;
                            objvaluespec.key_Col_Value = propvalue.ToString();
                            objvaluespec.AddUser_id = WebSecurity.CurrentUserId;
                            objvaluespec.mod_user_Id = WebSecurity.CurrentUserId;
                            objvaluespec.Add_Datetime = System.DateTime.Now;
                            objvaluespec.Mod_Datetime = System.DateTime.Now;
                            db.Value_Specification.Add(objvaluespec);
                            db.SaveChanges();
                            }
                        }

                    }

                    TempData["Message"] = ConfigurationManager.AppSettings["INS_SUC"];

                    ModelState.Clear();

                }

                catch(Exception exception ){
                    var queryError = from c in db.Menus
                                 where !(from o in db.menuTrees
                                         where o.Parent_Menuid != 0
                                         select o.Menu_id)
                                        .Contains(c.Mnu_id)
                                 select new { c.Mnu_id, c.Mnu_Name };
                    ViewBag.Menus = new SelectList(queryError, "mnu_Id", "Mnu_Name", "--Select Category--");
                    ViewBag.Brands = new SelectList(db.Brands.Where(act => act.IsActive == true), "BRND_id", "BRND_Name", "--Select Brand--");
                    ViewBag.Sub_category = new SelectList(db.Spec_category, "spec_cat_id", "spec_cat_Name", "--Select Sub--");
                    ViewBag.offers = new SelectList(db.OFFER_VALUE_TYPE, "OFR_VAl_Type_Id", "Ofr_Value_type");
                    return View(product);
                }

                return RedirectToAction("Create", "Admin");

            }
            var query = from c in db.Menus
                        where !(from o in db.menuTrees
                                where o.Parent_Menuid != 0
                                select o.Menu_id)
                               .Contains(c.Mnu_id)
                        select new { c.Mnu_id, c.Mnu_Name };
            ViewBag.Menus = new SelectList(query, "mnu_Id", "Mnu_Name", "--Select Category--");
            ViewBag.Brands = new SelectList(db.Brands.Where(act => act.IsActive == true), "BRND_id", "BRND_Name", "--Select Brand--");
            ViewBag.Sub_category = new SelectList(db.Spec_category, "spec_cat_id", "spec_cat_Name", "--Select Sub--");
            ViewBag.offers = new SelectList(db.OFFER_VALUE_TYPE, "OFR_VAl_Type_Id", "Ofr_Value_type");
            return View(product);
        }