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() }); }
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(); } }
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); }
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(); } }
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(); } }
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!"); }); }); }
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()); }
public static void Initialize(DNSContext context) { InitKinds(context); InitBranchs(context); InitProducts(context); InitCharacteristics(context); InitResidues(context); InitProductPrices(context); InitProductCharacteristics(context); }
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(); } }
public ActionResult Index() { using (DNSContext db = new DNSContext()) { Product product1 = new Product { Name = "Asus" }; db.Products.Add(product1); db.SaveChanges(); } return(View()); }
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(); } }
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(); } }
// 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")); } }
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()); }
static public List <FatProduct> FatProducts(DNSContext db) { return(FatProductsQuery(db).ToList()); }
static public FatProduct FatProducts(DNSContext db, String ProductId) { return((from item in FatProductsQuery(db) where item.Product.Id == ProductId select item).FirstOrDefault()); }
public ProductsController(DNSContext context) { db = context; }
public BranchsController(DNSContext context) { db = context; }
static public List <CharacteristicValue> CharacteristicValues(DNSContext db, String CharacteristicId) { return(db.CharacteristicValues .Where(item => item.CharacteristicId == CharacteristicId) .ToList()); }
public ProductCharacteristicsController(DNSContext context) { db = context; }
public CharacteristicValuesController(DNSContext context) { db = context; }
public PromotionsController(DNSContext context) { db = context; }
static public List <Kind> Kind(DNSContext db, String KindId) { return(db.Kinds .Where(item => item.Id == KindId) .ToList()); }
static public List <Kind> Kinds(DNSContext db) { return(db.Kinds.ToList()); }
public KindsController(DNSContext context) { db = context; }
static public List <Characteristic> Characteristics(DNSContext db) { return(db.Characteristics.Include(i => i.Variants).ToList()); }
public AccountController(DNSContext context) { db = context; }
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(); }
public ResiduesController(DNSContext context) { db = context; }
public BaseController(ILogger logger, DNSContext context) { Context = context; Logger = logger; }