예제 #1
0
        private List <MfProjectModel> GetPartModel(MfModelDicts dicts, ModelLists list, TraceSource ts, string url)
        {
            var ms    = new List <MfProjectModel>();
            var m     = (ProjectModel)_model;
            var group = MfProjectModel.GroupArrays(m.Elements, MaxCount);

            ts.TraceInformation("分组个数:" + group.Count);
            foreach (var g in group)
            {
                ts.TraceInformation("每组个数:" + g.Count);
                var pModel = new MfProjectModel {
                    Dicts = dicts, ModelUrl = url
                };
                FillModelProps(pModel);
                var mm = new ProjectModel {
                    Id = m.Id, Name = m.Name, Project = m.Project
                };
                mm.Elements.AddRange(g);
                pModel.Model = mm;
                pModel.Lists = list;
                ms.Add(pModel);
            }

            return(ms);
        }
예제 #2
0
        public async Task <ActionResult> Edit([Bind(Include = "ProductID,ProductCode,ProductName,ShortDescription,LongDescription,Quantity,MSRP,Price,WildmanPrice,Length,Width,Height,ParcelPost,InactiveProduct,NoBackOrders,LimitOne,New,KeepInventory,SpecialOrder,FeaturedProduct,ClassID")] Product product, HttpPostedFileBase[] files, string returnUrl)
        {
            for (int i = 0; i < files.Length; i++)
            {
                if (files[i] != null && files[i].ContentLength > 0)
                {
                    var extension = Path.GetExtension(files[i].FileName);
                    if (extension != ".png" && extension != ".jpg" && extension != ".jpeg")
                    {
                        ViewBag.Message = "One or more files has an invalid file extension";
                        return(View(product));
                    }
                }
            }
            if (ModelState.IsValid)
            {
                db.Entry(product).State = EntityState.Modified;
                await db.SaveChangesAsync();

                for (int i = 0; i < files.Length; i++)
                {
                    if (files[i] != null && files[i].ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(files[i].FileName);
                        path = Path.Combine(Server.MapPath("~/images"), fileName);
                        ProductImages image = new ProductImages();
                        image.Path      = "~/images/" + fileName;
                        image.ProductID = product.ProductID;
                        image.Featured  = false;
                        files[i].SaveAs(path);
                        if (i == 0)
                        {
                            /*Ensure that at least one image is set as featured*/
                            ProductImages images = ModelLists.ProductImages.Where(x => x.ProductID == product.ProductID && x.Featured == true).OrderByDescending(x => x.Featured).SingleOrDefault();
                            if (images == null)
                            {
                                image.Featured = true;
                            }
                        }
                        db.ProductImages.Add(image);
                        await db.SaveChangesAsync();
                    }
                }
                ModelLists.NewModelList();
                HierarchicalModelLists.NewHierarchicalModelLists();

                if (product.InactiveProduct)
                {
                    return(RedirectToAction("Index"));
                }

                if (!string.IsNullOrEmpty(returnUrl))
                {
                    return(Redirect(returnUrl));
                }

                return(RedirectToAction("Index"));
            }
            return(View(product));
        }
        public async Task <ActionResult> Create([Bind(Include = "ClassId,ClassName,ParentClassID,Description,ImageUrl")] Category menu, HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                var fileName = Path.GetFileName(file.FileName);
                path          = Path.Combine(Server.MapPath("~/images"), fileName);
                menu.ImageUrl = "~/images/" + fileName;
            }
            try
            {
                if (ModelState.IsValid)
                {
                    if (file != null && file.ContentLength > 0)
                    {
                        file.SaveAs(path);
                    }
                    db.MenuItems.Add(menu);
                    await db.SaveChangesAsync();

                    ModelLists.NewModelList();
                    HierarchicalModelLists.NewHierarchicalModelLists();

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                ViewBag.Message = "Image must be PNG or JPG file";
                return(View(menu));
            }

            return(View(menu));
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            Category menu = await db.MenuItems.FindAsync(id);

            db.MenuItems.Remove(menu);
            await db.SaveChangesAsync();

            ModelLists.NewModelList();
            HierarchicalModelLists.NewHierarchicalModelLists();
            return(RedirectToAction("Index"));
        }
예제 #5
0
        public async Task <ActionResult> PrimaryImage(int productID, int id)
        {
            wildman1Entities1 dbp = new wildman1Entities1();

            dbp.Make_Featured_Image(productID, id);
            await dbp.SaveChangesAsync();

            ModelLists.NewModelList();
            HierarchicalModelLists.NewHierarchicalModelLists();
            List <ProductImages> images = ModelLists.ProductImages.Where(x => x.ProductID == productID).OrderByDescending(x => x.Featured).ToList();

            return(PartialView("_EditImage", images));
        }
예제 #6
0
        public async Task <ActionResult> Create([Bind(Include = "ProductID,ProductCode,ProductName,ShortDescription,LongDescription,Quantity,MSRP,Price,WildmanPrice,Length,Width,Height,ParcelPost,InactiveProduct,NoBackOrders,LimitOne,New,KeepInventory,SpecialOrder,FeaturedProduct,ClassID")] Product product, HttpPostedFileBase[] files)
        {
            for (int i = 0; i < files.Length; i++)
            {
                if (files[i] != null && files[i].ContentLength > 0)
                {
                    var extension = Path.GetExtension(files[i].FileName);
                    if (extension != ".png" && extension != ".jpg" && extension != ".jpeg")
                    {
                        ViewBag.Message = "One or more files has an invalid file extension";
                        return(View(product));
                    }
                }
            }
            try
            {
                if (ModelState.IsValid)
                {
                    db.Products.Add(product);
                    await db.SaveChangesAsync();

                    for (int i = 0; i < files.Length; i++)
                    {
                        if (files[i] != null && files[i].ContentLength > 0)
                        {
                            var fileName = Path.GetFileName(files[i].FileName);
                            path = Path.Combine(Server.MapPath("~/images"), fileName);
                            ProductImages image = new ProductImages();
                            image.Path      = "~/images/" + fileName;
                            image.ProductID = product.ProductID;
                            if (i == 0)
                            {
                                image.Featured = true;
                            }
                            files[i].SaveAs(path);
                            db.ProductImages.Add(image);
                            await db.SaveChangesAsync();
                        }
                    }
                    ModelLists.NewModelList();
                    HierarchicalModelLists.NewHierarchicalModelLists();
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                return(View(product));
            }

            return(View(product));
        }
예제 #7
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            wildman1Entities1 dbp     = new wildman1Entities1();
            Product           product = await db.Products.FindAsync(id);

            db.Products.Remove(product);
            await db.SaveChangesAsync();

            dbp.Delete_All_Product_Images(id);
            await dbp.SaveChangesAsync();

            ModelLists.NewModelList();
            HierarchicalModelLists.NewHierarchicalModelLists();
            return(RedirectToAction("Index"));
        }
예제 #8
0
        public async Task <ActionResult> DeleteImage(int id, int productID)
        {
            ProductImages image = await db.ProductImages.Where(x => x.ID == id).SingleAsync();

            db.ProductImages.Remove(image);
            await db.SaveChangesAsync();

            ModelLists.NewModelList();
            HierarchicalModelLists.NewHierarchicalModelLists();
            List <ProductImages> images        = ModelLists.ProductImages.Where(x => x.ProductID == productID).ToList();
            List <ProductImages> defaultImages = ModelLists.ProductImages.Where(x => x.ProductID == productID && x.Featured).ToList();

            if (images.Count > 0 && defaultImages.Count == 0)
            {
                images[0].Featured        = true;
                db.Entry(images[0]).State = EntityState.Modified;
                await db.SaveChangesAsync();
            }

            return(PartialView("_EditImage", images));
        }
예제 #9
0
        private MfProjectModel GetBasicModel(ModelLists list, string url)
        {
            var m      = (ProjectModel)_model;
            var pModel = new MfProjectModel {
                ModelUrl = url
            };

            FillModelProps(pModel);
            var mm = new ProjectModel();

            mm.Categories.AddRange(m.Categories);
            mm.Families.AddRange(m.Families);
            mm.Id = m.Id;
            mm.Levels.AddRange(m.Levels);
            mm.Materials.AddRange(m.Materials);
            mm.Name    = m.Name;
            mm.Project = m.Project;
            mm.Types.AddRange(m.Types);
            mm.Views.AddRange(m.Views);
            pModel.Model = mm;
            pModel.Lists = list;
            return(pModel);
        }
        public async Task <ActionResult> Index([Bind(Include = "Name,Addr1,Country,City,State,PostalCode,email,phone,Comments,ShipName,ShipAddr1,ShipCountry,ShipCity,ShipState,ShipPostalCode,CardType,CardNumber,CVC,ExpirationDate,CardHolderName")] Order order)
        {
            bool flag = false;

            if (order.CardHolderName == null)
            {
                ViewBag.CardHolderName = "The Cardholder Name field is required";
                flag = true;
            }
            if (order.CardNumber == null)
            {
                ViewBag.CardNumber = "The Card Number field is required";
                flag = true;
            }
            if (order.CardType == null)
            {
                ViewBag.CardType = "Thie Card Type field is required";
                flag             = true;
            }
            if (order.CVC == null)
            {
                ViewBag.CVC = "The CVC field is required";
                flag        = true;
            }
            if (order.ExpirationDate == null)
            {
                ViewBag.ExpirationDate = "The Expiration Date field is required";
                flag = true;
            }
            if (flag)
            {
                return(View(order));
            }

            ShoppingCart cart          = ShoppingCart.GetCart(this);
            var          shoppingCarts = db.ShoppingCarts.Include("Product").Where(x => x.CartID == User.Identity.Name).ToList();

            string[]      creditDetails = { order.CardHolderName, order.CardType, order.CVC, order.ExpirationDate, Encryption.Encrypt(order.CardNumber) };
            StringBuilder sb            = new StringBuilder();

            for (int i = 0; i < creditDetails.Length; i++)
            {
                if (i == creditDetails.Length - 1)
                {
                    sb.Append(creditDetails[i]);
                }
                else
                {
                    sb.Append(creditDetails[i]).Append("_");
                }
            }

            order.OrderDate = DateTime.Now;
            order.UserName  = User.Identity.Name;
            order.Total     = cart.GetCartDecimalTotal();
            order.Details   = sb.ToString();

            if (ModelState.IsValid)
            {
                db.Orders.Add(order);

                foreach (var shoppingCart in shoppingCarts)
                {
                    decimal price;
                    if (shoppingCart.Product.WildmanPrice != null)
                    {
                        price = shoppingCart.Product.WildmanPrice ?? 0;
                    }
                    else
                    {
                        price = shoppingCart.Product.Price;
                    }
                    OrderItem orderItem = new OrderItem
                    {
                        Cost          = price,
                        ProductID     = shoppingCart.ProductID,
                        Quantity      = shoppingCart.Quantity,
                        OrderDetailID = order.OrderID
                    };
                    db.OrderItems.Add(orderItem);
                    db.ShoppingCarts.Remove(shoppingCart);
                    Product product = db.Products.Find(shoppingCart.ProductID);
                    product.Quantity       -= shoppingCart.Quantity;
                    product.Quantity        = (product.Quantity < 0) ? 0 : product.Quantity;
                    db.Entry(product).State = EntityState.Modified;
                }
                await db.SaveChangesAsync();

                ModelLists.NewModelList();
            }

            return(RedirectToAction("OrderReview", new { id = order.OrderID }));
        }
예제 #11
0
        private List <MfProjectModel> GetBasicModels(ModelLists list, TraceSource log, string url)
        {
            var listWithoutParts = new ModelLists();

            listWithoutParts.Cates.AddRange(list.Cates);
            listWithoutParts.Fams.AddRange(list.Fams);
            listWithoutParts.Floors.AddRange(list.Floors);
            listWithoutParts.Mats.AddRange(list.Mats);
            listWithoutParts.Types.AddRange(list.Types);
            listWithoutParts.Views.AddRange(list.Views);
            var m          = (ProjectModel)_model;
            var pModelList = new List <MfProjectModel>();

            if (m.Categories.Count + m.Families.Count + m.Levels.Count + m.Materials.Count + m.Types.Count +
                m.Views.Count < MaxCount)
            {
                var pModel = new MfProjectModel {
                    ModelUrl = url
                };
                FillModelProps(pModel);
                var mm = new ProjectModel {
                    Id = m.Id, Name = m.Name, Project = m.Project
                };
                mm.Categories.AddRange(m.Categories);
                mm.Families.AddRange(m.Families);
                mm.Levels.AddRange(m.Levels);
                mm.Views.AddRange(m.Views);
                mm.Materials.AddRange(m.Materials);
                mm.Types.AddRange(m.Types);
                pModel.Model = mm;
                pModel.Lists = listWithoutParts;
                pModelList.Add(pModel);
            }
            else
            {
                var pModel1 = new MfProjectModel {
                    ModelUrl = url
                };
                FillModelProps(pModel1);
                var mm1 = new ProjectModel {
                    Id = m.Id, Name = m.Name, Project = m.Project
                };
                mm1.Categories.AddRange(m.Categories);
                mm1.Families.AddRange(m.Families);
                mm1.Levels.AddRange(m.Levels);
                mm1.Views.AddRange(m.Views);
                mm1.Materials.AddRange(m.Materials);

                pModel1.Model = mm1;
                pModel1.Lists = listWithoutParts;
                pModelList.Add(pModel1);

                var pModel = new MfProjectModel {
                    ModelUrl = url
                };
                FillModelProps(pModel);
                var mm = new ProjectModel();
                mm.Id      = m.Id;
                mm.Name    = m.Name;
                mm.Project = m.Project;
                mm.Types.AddRange(m.Types);

                pModel.Model = mm;
                pModel.Lists = listWithoutParts;
                pModelList.Add(pModel);
            }

            return(pModelList);
        }