示例#1
0
        public ActionResult DeleteConfirmed(ViewTasteDelete model)
        {
            ShopProductsTaste taste = db.ShopProductsTastes
                                      .Include(b => b.ShopProducts)
                                      .Where(b => b.Id == model.Id)
                                      .SingleOrDefault();

            if (model.DeleteAll)
            {
                if (taste.ShopProducts != null)
                {
                    foreach (ShopProduct product in taste.ShopProducts)
                    {
                        List <ShopProductsPrice> removePrices = db.ShopProductsPrices.Where(p => p.ShopProduct.Id == product.Id).ToList();
                        db.ShopProductsPrices.RemoveRange(removePrices);
                        db.SaveChanges();

                        string dirPath = HttpContext.Server.MapPath("~/Content/Images/Shop/Products");
                        product.PhotoName       = Image.Delete(dirPath, product.PhotoName);
                        db.Entry(product).State = EntityState.Modified;
                        db.SaveChanges();
                    }

                    db.ShopProducts.RemoveRange(taste.ShopProducts);
                    db.SaveChanges();
                }
            }

            db.ShopProductsTastes.Remove(taste);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#2
0
 public ActionResult Edit(ShopProductsTaste shopProductsTaste)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shopProductsTaste).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(shopProductsTaste));
 }
示例#3
0
        public ActionResult Create(ShopProductsTaste shopProductsTaste)
        {
            if (ModelState.IsValid)
            {
                db.ShopProductsTastes.Add(shopProductsTaste);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(shopProductsTaste));
        }
示例#4
0
        //==========================================================



        //==========================================================
        // GET: AdminPanel/Tastes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShopProductsTaste shopProductsTaste = db.ShopProductsTastes.Find(id);

            if (shopProductsTaste == null)
            {
                return(HttpNotFound());
            }
            return(View(shopProductsTaste));
        }
示例#5
0
        //==========================================================



        //==========================================================
        // GET: AdminPanel/Tastes/Delete/5
        public ActionResult Delete(int?id)
        {
            ShopProductsTaste taste = db.ShopProductsTastes
                                      .Include(b => b.ShopProducts)
                                      .Where(b => b.Id == id)
                                      .SingleOrDefault();

            if (taste == null)
            {
                return(HttpNotFound());
            }

            ViewTasteDelete model = new ViewTasteDelete
            {
                Id            = taste.Id,
                Name          = taste.Name,
                Products      = taste.ShopProducts,
                ProductsCount = taste.ShopProducts.Count,
                DeleteAll     = false
            };

            return(View(model));
        }
示例#6
0
        protected override void Seed(ShopRosKvartal.Models.ApplicationDbContext context)
        {
            var userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(context));
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));

            //============================================================
            //инициализация ролей
            if (!context.Roles.Any())
            {
                // создание роли
                var role = new IdentityRole {
                    Name = "Администратор"
                };
                // добавление роли в бд
                roleManager.Create(role);

                role = new IdentityRole {
                    Name = "Модератор"
                };
                roleManager.Create(role);

                role = new IdentityRole {
                    Name = "Покупатель"
                };
                roleManager.Create(role);
            }
            //============================================================

            //============================================================
            //создание админа для пустой БД
            var admin = userManager.FindByName("Admin");

            if (admin == null || !context.Users.Any())
            {
                // создание админа
                admin = new ApplicationUser {
                    Email = "*****@*****.**", UserName = "******"
                };
                string password = "******";
                var    result   = userManager.Create(admin, password);

                // если создание пользователя прошло успешно
                if (result.Succeeded)
                {
                    var role = roleManager.FindByName("Администратор");
                    if (role != null)
                    {
                        // добавляем для пользователя роль
                        userManager.AddToRole(admin.Id, role.Name);
                    }
                    else
                    {
                        // создание роли
                        role = new IdentityRole {
                            Name = "Администратор"
                        };
                        // добавление роли в бд
                        roleManager.Create(role);
                        // добавляем для пользователя роль
                        userManager.AddToRole(admin.Id, role.Name);
                    }
                }
            }
            //============================================================

            //============================================================
            //инициализация SMTP сервера
            if (!context.ToolsSMTPSettings.Any())
            {
                ToolsSMTPSetting smtp = new ToolsSMTPSetting();
                smtp.EmailFrom = "*****@*****.**";
                smtp.UserName  = "******";
                smtp.Password  = "******";
                smtp.Host      = "smtp.gmail.com";
                smtp.Port      = 587;
                smtp.EnableSsl = true;
                context.ToolsSMTPSettings.Add(smtp);
                context.SaveChanges();
            }
            //============================================================

            //============================================================
            //инициализация таблицы полов пользователей
            if (!context.UserGenders.Any())
            {
                UserGender gender = new UserGender();
                gender.Gender = "Мужской";
                context.UserGenders.Add(gender);
                context.SaveChanges();

                gender.Gender = "Женский";
                context.UserGenders.Add(gender);
                context.SaveChanges();
            }
            //============================================================

            //============================================================
            //инициализация таблицы категории
            if (!context.ShopCategories.Any())
            {
                ShopCategory parent = new ShopCategory();
                parent.Name  = "Спортивное питание";
                parent.Alias = Translit.TranslitString(parent.Name);
                context.ShopCategories.Add(parent);
                context.SaveChanges();

                //-----------------------------------------------
                ShopCategory child = new ShopCategory {
                    Name     = "Протеины",
                    ParentId = parent.Id
                };
                child.Alias = Translit.TranslitString(child.Name);
                context.ShopCategories.Add(child);
                context.SaveChanges();
                //-----------------------------------------------
                child = new ShopCategory
                {
                    Name     = "Гейнеры",
                    ParentId = parent.Id
                };
                child.Alias = Translit.TranslitString(child.Name);
                context.ShopCategories.Add(child);
                context.SaveChanges();
            }
            //============================================================

            //============================================================
            //инициализация таблицы вкус товара
            if (!context.ShopProductsTastes.Any())
            {
                string[] tastes = { "Ваниль", "Клубника", "Шоколад", "Карамель-ваниль", "Малина-шоколад", "Миндаль-шоколад",
                                    "Малина", "Банан",    "Вишня",   "Абрикос",         "Персик",         "Апельсин" };
                for (int i = 0; i < tastes.Length; i++)
                {
                    ShopProductsTaste taste = new ShopProductsTaste
                    {
                        Name = tastes[i]
                    };
                    context.ShopProductsTastes.Add(taste);
                    context.SaveChanges();
                }
            }
            //============================================================

            //============================================================
            //инициализация таблицы брэнды
            if (!context.ShopProductsBrands.Any())
            {
                string[] brands = { "Optimum Nutrition",
                                    "Multipower",
                                    "BSN",
                                    "Dymatize",
                                    "MuscleTech",
                                    "Weider",
                                    "Sponser",
                                    "Twinlab",
                                    "Gaspari Nutrition",
                                    "Universal Nutrition" };
                for (int i = 0; i < brands.Length; i++)
                {
                    ShopProductsBrand brand = new ShopProductsBrand
                    {
                        Name  = brands[i],
                        Alias = brands[i].Replace(" ", "-")
                    };
                    context.ShopProductsBrands.Add(brand);
                    context.SaveChanges();
                }
            }
            //============================================================
        }