public static bool HasValue(this ShopDataModel shop) { if (shop != null) { return(true); } else { return(false); } }
public int AddItems(IEnumerable <Item> items, Shop shop, string username) { using (DataBaseModel context = new DataBaseModel()) { ShopDataModel shopDataModel = context.Set <ShopDataModel>() .Select(x => x) .Where(x => x.Name == shop.Name && x.Location == shop.Location) .FirstOrDefault() ?? new ShopDataModel() { Location = shop.Location, Name = shop.Name }; UserDataModel userDataModel = context.Set <UserDataModel>() .Select(x => x).Where(x => x.Username == username).FirstOrDefault(); if (userDataModel == null) { throw new System.Exception(Properties.Resources.UserNotFound); } ReceiptDataModel receiptDataModel = new ReceiptDataModel() { Shop = shopDataModel, User = userDataModel, Total = 0 }; receiptDataModel.Items = new List <ItemDataModel>(); foreach (Item item in items) { receiptDataModel.Items.Add(new ItemDataModel() { Receipt = receiptDataModel, Price = item.Price, Name = item.Name, Category = item.Category }); receiptDataModel.Total += item.Price; } context.Set <ReceiptDataModel>().Add(receiptDataModel); context.SaveChanges(); return(receiptDataModel.ReceiptId); } }
public CategoriesDao() { model = new ShopDataModel(); }
protected override void Seed(GREEDY.Data.DataBaseModel context) { // This method will be called after migrating to the latest version. var Shops = new ShopDataModel[] { new ShopDataModel() { Name = "IKI", Location = new Geocoding.Location(54.678853, 25.278207), Address = "Pylimo g. 21, Vilnius", SubName = "Palink" }, new ShopDataModel() { Name = "IKI", Location = new Geocoding.Location(54.728869, 25.269291), Address = "Didlaukio g. 80A, Vilnius", SubName = "Palink" }, new ShopDataModel() { Name = "IKI", Location = new Geocoding.Location(54.687653, 25.275257), Address = "Gedimino pr. 28, Vilnius", SubName = "Palink" }, new ShopDataModel() { Name = "IKI", Location = new Geocoding.Location(54.670692, 25.281783), Address = "Sodu g. 22, Vilnius", SubName = "Palink" }, new ShopDataModel() { Name = "IKI", Location = new Geocoding.Location(54.673236, 25.274738), Address = "Mindaugo g. 25, Vilnius", SubName = "Palink" }, new ShopDataModel() { Name = "IKI", Location = new Geocoding.Location(54.722358, 25.297907), Address = "Zirmunu g. 145, Vilnius", SubName = "Palink" }, new ShopDataModel() { Name = "IKI", Location = new Geocoding.Location(54.725833, 25.299526), Address = "Zirmunu g. 106, Vilnius", SubName = "Palink" }, new ShopDataModel() { Name = "MAXIMA", Location = new Geocoding.Location(54.678095, 25.272716), Address = "Mindaugo g. 11, Vilnius" }, new ShopDataModel() { Name = "MAXIMA", Location = new Geocoding.Location(54.727977, 25.278374), Address = "Didlaukio g. 1, Vilnius" }, new ShopDataModel() { Name = "MAXIMA", Location = new Geocoding.Location(54.682208, 25.255373), Address = "M. K. Ciurlionio g. 82, Vilnius" }, new ShopDataModel() { Name = "MAXIMA", Location = new Geocoding.Location(54.848567, 25.466849), Address = "Svencioniu g. 44, Nemencine 15174, Lietuva" }, new ShopDataModel() { Name = "RIMI", Location = new Geocoding.Location(54.708354, 25.313375), Address = "Antakalnio g. 55, Vilnius" }, new ShopDataModel() { Name = "RIMI", Location = new Geocoding.Location(54.678257, 25.287651), Address = "Didžioji g. 28, Vilnius" }, new ShopDataModel() { Name = "RIMI", Location = new Geocoding.Location(54.673904, 25.213369), Address = "Architektu g. 19, Vilnius" }, new ShopDataModel() { Name = "RIMI", Location = new Geocoding.Location(54.687019, 25.281393), Address = "Gedimino pr. 9, Vilnius" }, new ShopDataModel() { Name = "LIDL", Location = new Geocoding.Location(54.672603, 25.256474), Address = "Zemaites g. 16" }, new ShopDataModel() { Name = "LIDL", Location = new Geocoding.Location(54.673994, 25.296879), Address = "Rasu g. 9A" }, new ShopDataModel() { Name = "LIDL", Location = new Geocoding.Location(54.713697, 25.28571), Address = "Kalvariju g. 180" }, new ShopDataModel() { Name = "LIDL", Location = new Geocoding.Location(54.711871, 25.240719), Address = "Dukstu g. 34" }, new ShopDataModel() { Name = "LIDL", Location = new Geocoding.Location(54.693034, 25.219452), Address = "Sausio 13-osios g. 3" }, new ShopDataModel() { Name = "LIDL", Location = new Geocoding.Location(54.721467, 25.253155), Address = "Staneviciaus g. 2A" }, new ShopDataModel() { Name = "LIDL", Location = new Geocoding.Location(54.733398, 25.251695), Address = "Ateities g. 4A" }, new ShopDataModel() { Name = "LIDL", Location = new Geocoding.Location(54.729192, 25.216438), Address = "Justiniskiu g. 126" }, new ShopDataModel() { Name = "LIDL", Location = new Geocoding.Location(54.737923, 25.230966), Address = "S. Neries g. 16" }, new ShopDataModel() { Name = "IKI", SubName = "Palink", Location = new Geocoding.Location(0, 0) }, new ShopDataModel() { Name = "MAXIMA", Location = new Geocoding.Location(0, 0) }, new ShopDataModel() { Name = "RIMI", Location = new Geocoding.Location(0, 0) }, new ShopDataModel() { Name = "LIDL", Location = new Geocoding.Location(0, 0) }, new ShopDataModel() { Name = "NORFA", Location = new Geocoding.Location(0, 0) }, }; foreach (ShopDataModel shop in Shops) { if (context.Set <ShopDataModel>().FirstOrDefault(x => x.Name == shop.Name) == null) { context.Set <ShopDataModel>().Add(shop); } } context.SaveChanges(); }
public static Mock <DataBaseModel> GetDataBaseMock() { var Receipts = new ReceiptDataModel[] { new ReceiptDataModel { ReceiptId = 1 }, new ReceiptDataModel { ReceiptId = 2 }, new ReceiptDataModel { ReceiptId = 3 } }; var Shops = new ShopDataModel[] { new ShopDataModel { Name = "shop1", Location = new Location(0.0, 0.0), Address = "1600 Pennsylvania Ave SE, Washington, DC 20003, USA", ShopId = 1, Receipts = new ReceiptDataModel[] { Receipts[0], Receipts[2] } }, new ShopDataModel { Name = "shop2", Location = new Location(54.6760394, 25.2738736), Address = "Naugarduko g. 24, Vilnius 03225, Lithuania", ShopId = 2, Receipts = new ReceiptDataModel[] { Receipts[1] } } }; var Items = new ItemDataModel[] { new ItemDataModel { Name = "item1", ItemId = 1, Price = 1.00m, Category = "category", Receipt = Receipts[0] }, new ItemDataModel { Name = "item2", ItemId = 2, Price = 1.00m, Category = "category", Receipt = Receipts[0] }, new ItemDataModel { Name = "item3", ItemId = 3, Price = 1.00m, Category = "category", Receipt = Receipts[1] }, new ItemDataModel { Name = "item4", ItemId = 4, Price = 1.00m, Category = "category", Receipt = Receipts[1] }, new ItemDataModel { Name = "item5", ItemId = 5, Price = 1.00m, Category = "category", Receipt = Receipts[2] }, new ItemDataModel { Name = "item6", ItemId = 6, Price = 1.00m, Category = "category", Receipt = Receipts[2] }, new ItemDataModel { Name = "item7", ItemId = 7, Price = 1.00m, Category = "category", Receipt = Receipts[2] }, }; var Users = new UserDataModel[] { new UserDataModel() { Username = "******", Password = "******", Email = "email1", FullName = "FullName1", Receipts = new ReceiptDataModel[] { Receipts[0], Receipts[1] } }, new UserDataModel() { Username = "******", Password = "******", Email = "email2", FullName = "FullName2", Receipts = new ReceiptDataModel[] { Receipts[2] } }, }; Receipts[0].Items = new ItemDataModel[] { Items[0], Items[1] }; Receipts[0].Shop = Shops[0]; Receipts[0].User = Users[0]; Receipts[1].Items = new ItemDataModel[] { Items[2], Items[3] }; Receipts[1].Shop = Shops[1]; Receipts[1].User = Users[0]; Receipts[2].Items = new ItemDataModel[] { Items[4], Items[5], Items[6] }; Receipts[2].Shop = Shops[0]; Receipts[2].User = Users[1]; var mockReceipts = MockDbSet <ReceiptDataModel>(Receipts); var mockItems = MockDbSet <ItemDataModel>(Items); var mockUsers = MockDbSet <UserDataModel>(Users); var mockShops = MockDbSet <ShopDataModel>(Shops); var mockContext = new Mock <DataBaseModel>(); mockContext.Setup(x => x.Set <ReceiptDataModel>()).Returns(mockReceipts.Object); mockContext.Setup(x => x.Set <ShopDataModel>()).Returns(mockShops.Object); mockContext.Setup(x => x.Set <ItemDataModel>()).Returns(mockItems.Object); mockContext.Setup(x => x.Set <UserDataModel>()).Returns(mockUsers.Object); mockContext.Setup(x => x.Receipt).Returns(mockReceipts.Object); mockContext.Setup(x => x.Shop).Returns(mockShops.Object); mockContext.Setup(x => x.Item).Returns(mockItems.Object); mockContext.Setup(x => x.User).Returns(mockUsers.Object); return(mockContext); }
public PictureDao() { model = new ShopDataModel(); }
public LoginDao() { model = new ShopDataModel(); }
public TrademarkDao() { model = new ShopDataModel(); }
public ProductDao() { model = new ShopDataModel(); }