Exemplo n.º 1
0
 static private IQueryable <FatProduct> FatProductsQuery(DNSContext db)
 {
     return(from p in db.Products
            join kind in db.Kinds on p.KindId equals kind.Id
            join r in db.Residues on p.Id equals r.ProductId
            join price in db.ProductPrices on p.Id equals price.ProductId
            join c in db.ProductCharacteristics on p.Id equals c.ProductId
            where price.Branch.Name == "Владивосток" &&
            r.Branch.Name == "Владивосток"
            group c by new
     {
         Id = p.Id,
         Name = p.Name,
         Code = p.Code,
         Parent = p.Parent,
         Kind = kind,
         Residue = r.Value,
         Price = price.Value,
     } into g
            select new FatProduct
     {
         Product = new Product
         {
             Id = g.Key.Id,
             Name = g.Key.Name,
             Code = g.Key.Code,
             Parent = g.Key.Parent,
             Kind = g.Key.Kind
         },
         Residue = g.Key.Residue,
         Price = g.Key.Price,
         Characteristics = g.ToList()
     });
 }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 3
0
        protected override void Initialize(RequestContext requestContext)
        {
            using (var db = new DNSContext())
            {
                var setting = db.Settings.Single(s => s.Name.Equals(typeof(GeneralSettings).Name));
                var general = setting.GetValue(new GeneralSettings());
                ViewBag.Name    = general.Name;
                ViewBag.Address = general.Address;
                ViewBag.Phone   = general.Phone;
                ViewBag.Email   = general.Email;

                ViewBag.Footer    = general.Footer;
                ViewBag.Title     = general.Title;
                ViewBag.Desc      = general.Desc;
                ViewBag.Keyword   = general.KeyWord;
                ViewBag.CopyRight = general.CopyRight;

                ViewBag.Facebook   = general.Facebook;
                ViewBag.Twitter    = general.Twitter;
                ViewBag.GooglePlus = general.GooglePlus;
                ViewBag.Youtube    = general.Youtube;

                ViewBag.GoogleApi = general.GoogleApi;
            }

            base.Initialize(requestContext);
        }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
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();
            }
        }
Exemplo n.º 6
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DNSContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            dbContext.Database.Migrate();

            app.UseRouting();

            app.Use(async(context, nextMiddleware) =>
            {
                context.Response.OnStarting(() =>
                {
                    if (!context.Response.Headers.ContainsKey("Content-Type"))
                    {
                        context.Response.Headers.Add("Content-Type", "application/json");
                    }
                    return(Task.FromResult(0));
                });
                await nextMiddleware();
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();

                endpoints.MapGet("/", async context =>
                {
                    await context.Response.WriteAsync("Welcome to SharpNS REST API!");
                });
            });
        }
Exemplo n.º 7
0
        static public List <FatProduct> FatProducts(DNSContext db, List <String> ProductIds)
        {
            var query = FatProductsQuery(db);

            query = query.Where(item => ProductIds.Contains(item.Product.Id));

            return(query.ToList());
        }
Exemplo n.º 8
0
 public static void Initialize(DNSContext context)
 {
     InitKinds(context);
     InitBranchs(context);
     InitProducts(context);
     InitCharacteristics(context);
     InitResidues(context);
     InitProductPrices(context);
     InitProductCharacteristics(context);
 }
Exemplo n.º 9
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();
            }
        }
Exemplo n.º 10
0
        public ActionResult Index()
        {
            using (DNSContext db = new DNSContext())
            {
                Product product1 = new Product {
                    Name = "Asus"
                };

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

            return(View());
        }
Exemplo n.º 11
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();
            }
        }
Exemplo n.º 12
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();
            }
        }
Exemplo n.º 13
0
        // GET: DNSAdmin/Database
        public ActionResult GetBackup()
        {
            using (var db = new DNSContext())
            {
                var data = db.Articles.ToList().Aggregate("", (current, article) =>
                {
                    var s = new JavaScriptSerializer().Serialize(new ArticleBackup
                    {
                        Name    = article.Name,
                        Brief   = article.Brief,
                        Content = article.Content,
                        Id      = article.Id,

                        Mp3Url   = article.Mp3Url,
                        Mp3Error = article.Mp3Error,

                        Title           = article.Title,
                        MetaKeyword     = article.MetaKeyword,
                        MetaDescription = article.MetaDescription,
                        UrlKeyword      = article.UrlKeyword,
                        Type            = (int)article.Type,

                        Order           = article.Order,
                        Publish         = article.Publish,
                        PublishDate     = article.PublishedDate,
                        DateCreated     = article.DateCreated,
                        ArticleParentId = article.ArticleParentId,
                        ThumbnailUrl    = article.ThumbailUrl,
                        Catalogs        =
                            article.Catalogs.Aggregate("",
                                                       (c, catalog) => c + (string.IsNullOrWhiteSpace(c) ? catalog.Name : (";" + catalog.Name)))
                    });

                    current = string.IsNullOrWhiteSpace(current) ? s : (current + Environment.NewLine + s);
                    return(current);
                });

                var byteArray = Encoding.UTF8.GetBytes(data);
                var stream    = new MemoryStream(byteArray);

                return(File(stream, "text/plain", "backup-" + DateTime.Now.ToString("dd-MM-yyy-hh-mm-ss-tt") + ".txt"));
            }
        }
Exemplo n.º 14
0
        static public List <FatProduct> FatProducts(DNSContext db, Filter filter)
        {
            var query = FatProductsQuery(db);

            if (filter == null)
            {
                return(query.ToList());
            }

            if (filter.Name != "")
            {
                query = query.Where(item => item.Product.Name == filter.Name);
            }
            if (filter.Code != "")
            {
                query = query.Where(item => item.Product.Code == filter.Code);
            }
            query = query.Where(item => item.Price >= filter.MinPrice);
            query = query.Where(item => item.Price <= filter.MaxPrice);

            if (filter.Kinds.Count > 0)
            {
                query = query.Where(item => filter.Kinds.Contains(item.Product.Kind.Id));
            }

            foreach (var characteristic in filter.Characteristics)
            {
                query = query.Where(item =>
                                    item.Characteristics
                                    .Select(c => characteristic.Variants.Contains(c.CharacteristicValueId))
                                    .Contains(true)
                                    );
            }

            return(query.ToList());
        }
Exemplo n.º 15
0
 static public List <FatProduct> FatProducts(DNSContext db)
 {
     return(FatProductsQuery(db).ToList());
 }
Exemplo n.º 16
0
 static public FatProduct FatProducts(DNSContext db, String ProductId)
 {
     return((from item in FatProductsQuery(db)
             where item.Product.Id == ProductId
             select item).FirstOrDefault());
 }
Exemplo n.º 17
0
 public ProductsController(DNSContext context)
 {
     db = context;
 }
Exemplo n.º 18
0
 public BranchsController(DNSContext context)
 {
     db = context;
 }
Exemplo n.º 19
0
 static public List <CharacteristicValue> CharacteristicValues(DNSContext db, String CharacteristicId)
 {
     return(db.CharacteristicValues
            .Where(item => item.CharacteristicId == CharacteristicId)
            .ToList());
 }
Exemplo n.º 20
0
 public ProductCharacteristicsController(DNSContext context)
 {
     db = context;
 }
Exemplo n.º 21
0
 public CharacteristicValuesController(DNSContext context)
 {
     db = context;
 }
Exemplo n.º 22
0
 public PromotionsController(DNSContext context)
 {
     db = context;
 }
Exemplo n.º 23
0
 static public List <Kind> Kind(DNSContext db, String KindId)
 {
     return(db.Kinds
            .Where(item => item.Id == KindId)
            .ToList());
 }
Exemplo n.º 24
0
 static public List <Kind> Kinds(DNSContext db)
 {
     return(db.Kinds.ToList());
 }
Exemplo n.º 25
0
 public KindsController(DNSContext context)
 {
     db = context;
 }
Exemplo n.º 26
0
 static public List <Characteristic> Characteristics(DNSContext db)
 {
     return(db.Characteristics.Include(i => i.Variants).ToList());
 }
Exemplo n.º 27
0
 public AccountController(DNSContext context)
 {
     db = context;
 }
Exemplo n.º 28
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();
        }
Exemplo n.º 29
0
 public ResiduesController(DNSContext context)
 {
     db = context;
 }
Exemplo n.º 30
0
 public BaseController(ILogger logger, DNSContext context)
 {
     Context = context;
     Logger  = logger;
 }