示例#1
0
        public IActionResult Card(Product model, TableItemEvent e)
        {
            if (e == TableItemEvent.Delete)
            {
                var items = db.Products.Where(c => c.ParentId == model.Id).ToList();
                foreach (var item in items)
                {
                    item.ParentId = null;
                    db.Products.Update(item);
                }

                db.SaveChanges();
            }


            if (ModelState.IsValid || e == TableItemEvent.Delete)
            {
                db.Products.Change(model, e);
                db.SaveChanges();
                return(RedirectToAction("Tables", "Home", new { name = "Products" }));
            }
            else
            {
                return(Content($"Поля не удовлетворяют условиям"));
            }
        }
 public ActionResult Edit(StudyBibleMonthly monthly)
 {
     if (ModelState.IsValid)
     {
         if (monthly.Id == 0)
         {
             var setting = new Setting
             {
                 Name  = typeof(StudyBibleMonthly).Name,
                 Group = ((int)monthly.Month).ToString()
             };
             setting.SetValue(monthly);
             db.Settings.Add(setting);
             db.SaveChanges();
         }
         else
         {
             var setting = db.Settings.Find(monthly.Id);
             setting.SetValue(monthly);
             db.Entry(setting).State = EntityState.Modified;
             db.SaveChanges();
         }
         ViewBag.Update = "Cập nhật thành công!";
     }
     else
     {
         ViewBag.Error = "Cập nhật thất bại!";
     }
     return(View(monthly));
 }
示例#3
0
        public static void InitProducts(DNSContext context)
        {
            if (!context.Products.Any())
            {
                var rand = new Random();
                var i    = 0;
                foreach (var kind in Kinds)
                {
                    var kindid = context.Kinds.Where(k => k.Name == kind)
                                 .ToList()[0].Id;
                    foreach (int k in Enumerable.Range(0, rand.Next(1, 50)))
                    {
                        i++;
                        var products = context.Products.ToList();
                        var parentid = products.Count == 0 ?
                                       null : products[rand.Next(0, products.Count)].Id;
                        context.Products.Add(new Product()
                        {
                            Name     = "Product_" + rand.Next(10000000, 99999999).ToString(),
                            Code     = i.ToString(),
                            DelFlag  = rand.Next(0, 2) == 0,
                            KindId   = kindid,
                            ParentId = parentid
                        });
                        context.SaveChanges();
                    }
                }

                context.SaveChanges();
            }
        }
示例#4
0
        public static void InitCharacteristics(DNSContext context)
        {
            if (!context.Characteristics.Any())
            {
                var i = 0;
                foreach (var item in Characteristics)
                {
                    i++;
                    context.Characteristics.Add(new Characteristic()
                    {
                        Name = item.Key,
                        Code = i.ToString()
                    });
                    context.SaveChanges();
                    var j      = 0;
                    var lastid = context.Characteristics.Where(charct => charct.Code == i.ToString())
                                 .ToList()[0].Id;
                    foreach (var val in item.Value)
                    {
                        j++;
                        context.CharacteristicValues.Add(new CharacteristicValue()
                        {
                            Name             = val,
                            CharacteristicId = lastid,
                            Code             = j.ToString()
                        });
                    }
                }

                context.SaveChanges();
            }
        }
示例#5
0
        public static void InitProductCharacteristics(DNSContext context)
        {
            if (!context.ProductCharacteristics.Any())
            {
                var rand  = new Random();
                var i     = 0;
                var items = context.Products;

                foreach (var item in items)
                {
                    var characteristics = context.Characteristics;
                    foreach (var characteristic in characteristics)
                    {
                        var values = context.CharacteristicValues.
                                     Where(c => c.CharacteristicId == characteristic.Id).ToList();

                        i++;
                        if (characteristic == null)
                        {
                            Console.Write(true);
                        }

                        if (item == null)
                        {
                            Console.Write(true);
                        }

                        var val = values[rand.Next(0, values.Count)];

                        if (val == null)
                        {
                            Console.Write(true);
                        }

                        context.ProductCharacteristics.Add(new ProductCharacteristic()
                        {
                            CharacteristicId      = characteristic.Id,
                            ProductId             = item.Id,
                            CharacteristicValueId = val.Id
                        });
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            Console.Write(true);
                            return;
                        }
                    }
                }

                context.SaveChanges();
            }
        }
示例#6
0
        public ActionResult Create([Bind(Include = "Id,Name,ManagerTemplate,DisplayTemplate")] TypeInput typeInput)
        {
            if (ModelState.IsValid)
            {
                db.TypeInputs.Add(typeInput);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(typeInput));
        }
示例#7
0
        public ActionResult Import(string json)
        {
            var arr  = Regex.Split(json, "\r\n");
            var list = arr.Where(a => !string.IsNullOrWhiteSpace(a)).Select(a => new JavaScriptSerializer().Deserialize <MediaModel>(a.Substring(0, a.Length - 1))).ToList();

            foreach (var obj in list)
            {
                Catalog catalog;
                if (!db.Catalogs.Any(c => c.Name.Equals(obj.CategoryId)))
                {
                    catalog = new Catalog
                    {
                        Name            = obj.CategoryId,
                        UrlKeyWord      = MediaModel.ConvertToUnsign3(obj.CategoryId),
                        Publish         = true,
                        DateCreated     = DateTime.Now.ToLocalTime(),
                        Title           = obj.CategoryId,
                        CatalogParentId = 2,
                        ShowInMainMenu  = true,
                        AcceptDownload  = true
                    };
                    db.Catalogs.Add(catalog);
                    db.SaveChanges();
                }
                else
                {
                    catalog = db.Catalogs.Single(c => c.Name.Equals(obj.CategoryId));
                }
                var article = new Article
                {
                    Name = obj.Name,

                    DateCreated   = obj.PulishDate.ToLocalTime(),
                    PublishedDate = obj.PulishDate.ToLocalTime(),
                    UrlKeyword    = obj.GetUrlKeyword(),
                    Mp3Url        = obj.MediaUrl,
                    Mp3Error      = obj.IsError,
                    Catalogs      = new List <Catalog> {
                        catalog
                    },
                    Type    = ArticleType.Article,
                    Title   = obj.Name,
                    Publish = true
                };
                if (db.Articles.Any(a => a.Name == article.Name && a.PublishedDate == article.PublishedDate))
                {
                    continue;
                }
                db.Articles.Add(article);
                db.SaveChanges();
            }
            return(View(list));
        }
 public ActionResult Create(ContentType contentType)
 {
     if (ModelState.IsValid)
     {
         db.Database.ExecuteSqlCommand("DBCC CHECKIDENT ('ContentsOptionInputses', RESEED, 0)");
         contentType.ContentsOptionInputs = contentType.ContentsOptionInputs.Where(coi => !string.IsNullOrWhiteSpace(coi.Label)).ToList();
         db.ContentTypes.Add(contentType);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.TypeInputs = db.TypeInputs.ToList();
     return(View(contentType));
 }
        public ActionResult Create([Bind(Include = "Id,Name,UrlKeyWord,ThumbnailUrl,Brief,Desc,ShowInMainMenu,Url,CatalogParentId,Publish,Order")] Catalog catalog)
        {
            if (ModelState.IsValid)
            {
                catalog.DateCreated = DateTime.Now;
                db.Catalogs.Add(catalog);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CatalogParentId = new SelectList(CatalogResolve.GetSelectListAllLevelCatalog(db.Catalogs.Where(c => c.CatalogParentId == null).ToList()), "Id", "Name");
            return(View(catalog));
        }
示例#10
0
        public ActionResult Create(Article article)
        {
            if (ModelState.IsValid)
            {
                article.Type        = ArticleType.Page;
                article.DateCreated = DateTime.Now;
                db.Articles.Add(article);
                db.SaveChanges();
                return(article.Publish ? RedirectToAction("Index") : RedirectToAction("Edit", new { id = article.Id }));
            }

            ViewBag.ArticleParentId = new SelectList(db.Articles, "Id", "Name", article.ArticleParentId);
            return(View(article));
        }
示例#11
0
        public static void InitProductPrices(DNSContext context)
        {
            if (!context.ProductPrices.Any())
            {
                var rand  = new Random();
                var i     = 0;
                var items = context.Products;

                foreach (var item in items)
                {
                    var branchs = context.Branchs;
                    foreach (var branch in branchs)
                    {
                        i++;
                        context.ProductPrices.Add(new ProductPrice()
                        {
                            BranchId  = branch.Id,
                            ProductId = item.Id,
                            Value     = rand.Next(500, 20000)
                        });
                    }
                }

                context.SaveChanges();
            }
        }
示例#12
0
 public IActionResult Card(Residue model, TableItemEvent e)
 {
     if (ModelState.IsValid || e == TableItemEvent.Delete)
     {
         db.Residues.Change(model, e);
         db.SaveChanges();
         return(RedirectToAction("Tables", "Home", new { name = "Residues" }));
     }
     else
     {
         return(Content($"Поля не удовлетворяют условиям"));
     }
 }
示例#13
0
        public ActionResult Index()
        {
            using (DNSContext db = new DNSContext())
            {
                Product product1 = new Product {
                    Name = "Asus"
                };

                db.Products.Add(product1);
                db.SaveChanges();
            }

            return(View());
        }
示例#14
0
        public static void InitKinds(DNSContext context)
        {
            if (!context.Kinds.Any())
            {
                var i = 0;
                foreach (var kind in Kinds)
                {
                    i++;
                    context.Kinds.Add(new Kind()
                    {
                        Name = kind,
                        Code = i.ToString()
                    });
                }

                context.SaveChanges();
            }
        }
示例#15
0
        public static void InitBranchs(DNSContext context)
        {
            if (!context.Branchs.Any())
            {
                var i = 0;
                foreach (var branch in Branchs)
                {
                    i++;
                    context.Branchs.Add(new Branch()
                    {
                        Name = branch,
                        Code = i.ToString()
                    });
                }

                context.SaveChanges();
            }
        }
        public ActionResult General()
        {
            var     name = typeof(GeneralSettings).Name;
            Setting setting;

            //in it
            if (!db.Settings.Any(s => s.Name.Equals(name)))
            {
                setting = new Setting {
                    Name = typeof(GeneralSettings).Name
                };
                setting.SetValue(new GeneralSettings());
                db.Settings.Add(setting);
                db.SaveChanges();
            }
            setting = db.Settings.Single(s => s.Name.Equals(name));
            var gs = setting.GetValue(new GeneralSettings());

            gs.Id = setting.Id;
            return(View(gs));
        }
示例#17
0
        static void Main(string[] args)
        {
            string line;
            var    path = Directory.GetCurrentDirectory() + "\\data.txt";
            var    file = new StreamReader(path);

            while ((line = file.ReadLine()) != null)
            {
                line = line.Remove(line.Length - 1);

                var obj = new JavaScriptSerializer().Deserialize <MediaModel>(line);
                Console.WriteLine(obj.PulishDate.ToLocalTime());
                using (var db = new DNSContext())
                {
                    Catalog catalog;
                    if (!db.Catalogs.Any(c => c.Name.Equals(obj.CategoryId)))
                    {
                        catalog = new Catalog
                        {
                            Name            = obj.CategoryId,
                            UrlKeyWord      = ConvertToUnsign3(obj.CategoryId),
                            Publish         = true,
                            DateCreated     = DateTime.Now,
                            Title           = obj.CategoryId,
                            CatalogParentId = 2,
                            ShowInMainMenu  = true,
                            AcceptDownload  = true
                        };
                        db.Catalogs.Add(catalog);
                        db.SaveChanges();
                    }
                    //khong biet
                    else
                    {
                        catalog = db.Catalogs.Single(c => c.Name.Equals(obj.CategoryId));
                    }
                    var article = new Article
                    {
                        Name = obj.Name,

                        DateCreated   = obj.PulishDate.ToLocalTime(),
                        PublishedDate = obj.PulishDate.ToLocalTime(),
                        UrlKeyword    = ConvertToUnsign3(obj.Name) + "-" + obj.PulishDate.ToLocalTime().ToString("dMyyyy"),
                        Mp3Url        = obj.MediaUrl,
                        Mp3Error      = obj.IsError,
                        Catalogs      = new List <Catalog> {
                            catalog
                        },
                        Type    = ArticleType.Article,
                        Title   = obj.Name,
                        Publish = true
                    };
                    if (db.Articles.Any(a => a.Name == article.Name && a.PublishedDate == article.PublishedDate))
                    {
                        continue;
                    }
                    Console.WriteLine(article.PublishedDate);
                    db.Articles.Add(article);
                    db.SaveChanges();
                }
            }
            file.Close();
            Console.ReadLine();
        }