private static IQueryable <GoodViewModel> GoodViewModelBaseQuery(RaterPriceContext context) { var q = from g in context.Goods select new GoodViewModel { Id = g.Id, Name = g.Name, ShortName = g.ShortName, Barcode = g.Barcode, MaxPrice = (from p in context.Prices join s in context.Shops on p.ShopId equals s.Id select new GoodPriceViewModel { Price = p.PriceValue, ShopId = s.Id, ShopName = s.Name }).OrderBy( p => p.Price).FirstOrDefault(), MinPrice = (from p in context.Prices join s in context.Shops on p.ShopId equals s.Id select new GoodPriceViewModel { Price = p.PriceValue, ShopId = s.Id, ShopName = s.Name }) .OrderByDescending(p => p.Price).FirstOrDefault(), Images = (from i in context.Images where i.ObjectId == g.Id && i.ImageTypeId == (int)ImageType.GoodImage select new GoodImageViewModel { Name = i.FileName, IsMain = i.Main, Url = i.FileUrl }).ToList() }; return(q.OrderBy(g => g.Name)); }
private static List <Weekday> ImportWeekDays() { var days = Enum.GetValues(typeof(DaysOfWeek)).Cast <DaysOfWeek>().ToList(); var domainList = days.Select(d => new Weekday() { Id = (int)d, Name = d.ToString() }).ToList(); domainList = domainList.OrderBy(d => d.Id).ToList(); foreach (var d in domainList) { using (RaterPriceContext context = RaterPriceContext.Create()) { if (context.Weekdays.Any(da => da.Name == d.Name)) { continue; } d.Id = context.Weekdays.Add(d).Id; context.SaveChanges(); Console.WriteLine("Working day has been imported: " + d.Name); } } return(domainList); }
private static IQueryable <GoodViewModel> MostPopular(RaterPriceContext context) { var l = (GoodViewModelBaseQuery(context) .Select(g => g)).OrderBy(g => g.MinPrice.Price); return(l); }
private static IQueryable <GoodViewModel> FilterByName(string name, RaterPriceContext context) { var l = (GoodViewModelBaseQuery(context) .Where(g => g.Name.IndexOf(name) > -1).Select(g => g)); return(l); }
private static List <City> ImrportCities(string[] shops) { var citiesList = shops.Select(shop => shop.Split(';')[5]).ToList(); var groupedList = citiesList.GroupBy(x => x).Select(x => x.Key).ToList(); groupedList = groupedList.Where(g => !string.IsNullOrWhiteSpace(g)).Select(s => s).ToList(); var domainList = new List <City>(); using (RaterPriceContext context = RaterPriceContext.Create()) { foreach (var gr in groupedList) { var domainItem = new City() { Name = gr.Trim() }; if (!context.Cities.Any(g => g.Name.Equals(domainItem.Name))) { domainItem.Id = context.Cities.Add(domainItem).Id; context.SaveChanges(); Console.WriteLine("City has been imported: " + domainItem.Name); } else { domainItem.Id = context.Cities.Where(p => p.Name.Equals(domainItem.Name)).Select(p => p.Id).First(); } domainList.Add(domainItem); } } return(domainList); }
private static IQueryable <GoodViewModel> FilterByBarcode(string barcode, RaterPriceContext context) { var l = (GoodViewModelBaseQuery(context) .Where(g => g.Barcode.Equals(barcode)) .Select(g => g)); return(l); }
private static void FilterByCityId(RaterPriceContext context, int cityId, ref IQueryable<GoodViewModel> query) { var goodIdsInTheCity = from p in context.Prices join s in context.Shops on p.ShopId equals s.Id where s.CityId == cityId select p.GoodId; query = query.Where(g => goodIdsInTheCity.Contains(g.Id)); }
static void Main(string[] args) { var connectionString = ConfigurationManager.ConnectionStrings["raterPriceConnectionString"].ConnectionString; using (RaterPriceContext context = RaterPriceContext.Create()) { var goodsIdsWithPrices = context.Prices.Select(p => p.GoodId); var goodsWithoutPrice = context.Goods.Where(g => !goodsIdsWithPrices.Contains(g.Id)).Select(g => g).AsNoTracking().ToList(); if (!goodsWithoutPrice.Any()) { goodsWithoutPrice = context.Goods.Select(g => g).AsNoTracking().ToList(); } foreach (var good in goodsWithoutPrice) { var shopsIdsWithPrices = context.Prices.Select(p => p.ShopId); var shops = context.Shops.Where(s => !shopsIdsWithPrices.Contains(s.Id)).Select(s => s); if (shops.Count() < 2) { shops = context.Shops.Select(s => s); } var r1 = new Random(); var take = r1.Next(1, shops.Count() - 1); var skip = r1.Next(0, take - 1); var workingRange = shops.OrderBy(s => s.Id).Skip(() => skip).Take(() => take).AsNoTracking().ToList(); foreach (var shop in workingRange) { if (context.Prices.Any(p => p.ShopId == shop.Id && p.GoodId == good.Id)) { continue; } var r = new Random(); var price = new Price() { GoodId = good.Id, ShopId = shop.Id, DateUpdated = DateTime.UtcNow, PriceValue = Convert.ToDecimal(r.Next(1, 1000) + r.NextDouble()), UserId = r.Next() }; context.Prices.Add(price); context.SaveChanges(); Console.WriteLine(price.PriceValue + "->" + shop.Name + "->" + good.Name); } } } }
public void GetCitiesTest() { var connectionString = GetConnectionString(); var url = GetBaseUrl() + "/api/cities"; var r = Get(url); var list = new JavaScriptSerializer().Deserialize <List <City> >(r); using (var context = new RaterPriceContext()) { var cities = context.Cities.Select(c => c); Assert.AreEqual(list.Count(), cities.Count()); foreach (var c in cities) { var id = c.Id; var name = c.Name; Assert.AreEqual(list.Any(x => x.Name == name && x.Id == id), true); } } }
public void GetShopsTest() { var connectionString = GetConnectionString(); const int cityId = 8; const string querySearch = "О"; var url = GetBaseUrl() + $"api/shops/search?cityId={cityId}&querySearch={querySearch}"; var r = Get(url); var list = new JavaScriptSerializer().Deserialize <List <Shop> >(r); using (RaterPriceContext context = RaterPriceContext.Create()) { var shops = context.Shops.Where(s => s.CityId == cityId && s.Name.IndexOf(querySearch) > -1).Select(s => s); Assert.AreEqual(list.Count(), shops.Count()); foreach (var s in shops) { var shopId = s.Id; var shopCityId = s.CityId; var shopName = s.Name; Assert.AreEqual(list.Any(x => x.Name == shopName && x.Id == shopId && x.CityId == shopCityId), true); } } }
private static List <ShopGroup> ImrportGroups(string[] shops) { var groupsList = new List <string>(); foreach (var shop in shops) { var groupsForOneItem1 = shop.Split(';')[2]; var groupsForOneItem2 = shop.Split(';')[3]; groupsList.Add(groupsForOneItem1); groupsList.Add(groupsForOneItem2); } var groupedList = groupsList.GroupBy(x => x).Select(x => x.Key).ToList(); groupedList = groupedList.Where(g => !string.IsNullOrWhiteSpace(g)).Select(s => s).ToList(); var domainList = new List <ShopGroup>(); using (RaterPriceContext context = RaterPriceContext.Create()) { foreach (var gr in groupedList) { var domainItem = new ShopGroup() { Name = gr.Trim() }; if (!context.ShopGroups.Any(g => g.Name.Equals(domainItem.Name))) { domainItem.Id = context.ShopGroups.Add(domainItem).Id; context.SaveChanges(); Console.WriteLine("Group has been imported: " + domainItem.Name); } else { domainItem.Id = context.ShopGroups.Where(p => p.Name.Equals(domainItem.Name)).Select(p => p.Id).First(); } domainList.Add(domainItem); } } return(domainList); }
private static List <PaymentType> ImrportPaymentTypes(string[] shops) { var paymentTypeList = new List <string>(); foreach (var shop in shops) { var paymentTypesForOneItem = shop.Split(';')[30].Split(','); paymentTypeList.AddRange(paymentTypesForOneItem); } var groupedList = paymentTypeList.GroupBy(x => x).Select(x => x.Key).ToList(); groupedList = groupedList.Where(g => !string.IsNullOrWhiteSpace(g)).Select(s => s).ToList(); var domainList = new List <PaymentType>(); using (RaterPriceContext context = RaterPriceContext.Create()) { foreach (var pt in groupedList) { var domainItem = new PaymentType() { Name = pt.Trim() }; if (!context.PaymentTypes.Any(p => p.Name.Equals(domainItem.Name))) { domainItem.Id = context.PaymentTypes.Add(domainItem).Id; context.SaveChanges(); Console.WriteLine("Payment type has been imported: " + domainItem.Name); } else { domainItem.Id = context.PaymentTypes.Where(p => p.Name.Equals(domainItem.Name)).Select(p => p.Id).First(); } domainList.Add(domainItem); } } return(domainList); }
private static List <Shop> ImportShops(string[] shopsInStrings, List <Weekday> weekdays, List <PaymentType> paymentTypes, List <ShopGroup> groups, List <City> cities) { var domainShops = new List <Shop>(); foreach (var shopStr in shopsInStrings) { var domainShop = MapOneShopFromString(shopStr, groups, cities); using (RaterPriceContext context = RaterPriceContext.Create()) { domainShop.Id = context.Shops.Add(domainShop).Id; context.SaveChanges(); var paymentTypesForShop = GetPaymentTypesForShop(shopStr, paymentTypes, domainShop.Id); context.ShopPaymentTypes.AddRange(paymentTypesForShop); context.SaveChanges(); var shopWorkingDays = GetShopWeekdays(shopStr, weekdays, domainShop.Id); context.ShopWeekdays.AddRange(shopWorkingDays); context.SaveChanges(); } domainShops.Add(domainShop); Console.WriteLine("Shop has been imported: " + domainShop.Name); } return(domainShops); }
public UserService(RaterPriceContext raterPriceContext) { _raterPriceContext = raterPriceContext; }
public RoleStore(RaterPriceContext context) : base(context) { }
//private readonly IRaterPriceContext _context; public QueryFacade(RaterPriceContext raterPriceContext) { _raterPriceContext = raterPriceContext; //_context = context; }
public CommandFacade(RaterPriceContext raterPriceContext) { _raterPriceContext = raterPriceContext; }
public RegistrationService(RaterPriceContext raterPriceContext, ISmsService smsService, IUserService userService) { _raterPriceContext = raterPriceContext; _smsService = smsService; _userService = userService; }
public UserStore(RaterPriceContext context) : base(context) { }
public SmsService(ISmsGateWay smsGateWay, RaterPriceContext raterPriceContext) { _smsGateWay = smsGateWay; _raterPriceContext = raterPriceContext; }