public List <string> GetAllDistinctCategories()
 {
     using (DataBaseModel context = new DataBaseModel())
     {
         var distinctCategories = context.Set <CategoryDataModel>()
                                  .Select(x => x.Category).Distinct();
         return(distinctCategories.ToList());
     }
 }
Beispiel #2
0
 public List <Item> GetItemsOfSingleReceipt(int receiptId)
 {
     using (DataBaseModel context = new DataBaseModel())
     {
         var temp = context.Set <ReceiptDataModel>()
                    .FirstOrDefault(x => x.ReceiptId == receiptId);
         return(temp.Items.Select(x => new Item {
             Category = x.Category, Name = x.Name, Price = x.Price, ItemId = x.ItemId
         }).ToList());
     }
 }
Beispiel #3
0
        public LoginSession CreateNewSession(User user)
        {
            using (DataBaseModel context = new DataBaseModel())
            {
                var userDataModel = context.Set <UserDataModel>()
                                    .FirstOrDefault(x => x.Username == user.Username);

                var loginSessionDataModel = context.Set <LoginSessionDataModel>()
                                            .Add(new LoginSessionDataModel()
                {
                    SessionID = Guid.NewGuid(),
                    User      = userDataModel
                });
                context.SaveChanges();
                return(new LoginSession()
                {
                    SessionID = loginSessionDataModel.SessionID,
                    Username = userDataModel.Username
                });
            }
        }
Beispiel #4
0
 public List <Item> LoadData(string Username)
 {
     using (DataBaseModel context = new DataBaseModel())
     {
         var temp = context.Set <ItemDataModel>()
                    .Select(x => x)
                    .Where(x => x.Receipt.User.Username == Username);
         return(temp.Select(x => new Item {
             Category = x.Category, Name = x.Name, Price = x.Price
         }).ToList());
     }
 }
Beispiel #5
0
 public void AddUser(User user)
 {
     using (DataBaseModel context = new DataBaseModel())
     {
         context.Set <UserDataModel>()
         .Add(new UserDataModel()
         {
             Username = user.Username, Email = user.Email, Password = user.Password, FullName = user.Fullname
         });
         context.SaveChanges();
     }
 }
Beispiel #6
0
 public List <User> GetExistingUsers()
 {
     using (DataBaseModel context = new DataBaseModel())
     {
         return(context.Set <UserDataModel>()
                .Select(x => new User()
         {
             Email = x.Email, Username = x.Username, Fullname = x.FullName, Password = x.Password
         })
                .ToList());
     }
 }
Beispiel #7
0
        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);
            }
        }
Beispiel #8
0
 //TODO: for now this only saves the changed item to ItemDataModels table
 //nothing is written for categorizations.
 //Once categoraziation is sorted out need to add extra logic
 public void UpdateItem(Item UpdatedItem)
 {
     using (DataBaseModel context = new DataBaseModel())
     {
         var itemToUpdate = context.Set <ItemDataModel>()
                            .FirstOrDefault(x => x.ItemId == UpdatedItem.ItemId);
         //TODO: I believe this can be written in more SOLID style
         //Using explicit/implicit type conversion operators
         //Didn't have the time to research this
         itemToUpdate.Name     = UpdatedItem.Name;
         itemToUpdate.Category = UpdatedItem.Category;
         itemToUpdate.Price    = UpdatedItem.Price;
         context.SaveChanges();
     }
 }
Beispiel #9
0
 public bool AuthenticateSession(LoginSession session)
 {
     using (DataBaseModel context = new DataBaseModel())
     {
         var loginSessionDataModel = context.Set <LoginSessionDataModel>()
                                     .FirstOrDefault(x => x.SessionID == session.SessionID &&
                                                     x.User.Username == session.Username);
         if (loginSessionDataModel != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }