Beispiel #1
0
        public Collection <Category> GetUserReceiptCategories(string userId, int receiptId)
        {
            var domainCategories = new Collection <Category>();

            using (var db = new DatabaseModel.ReceiptReaderDatabaseContext())
            {
                var receipt = db.Receipt.FirstOrDefault(r => (r.UserId == userId) && (r.Id == receiptId));

                if (receipt == null)
                {
                    return(null);
                }

                var dbCategories = new List <DatabaseModel.Category>();

                foreach (var dbProduct in receipt.Product)
                {
                    dbCategories.Add(dbProduct.Category);
                }

                var distinctDbCategories = dbCategories.Distinct();

                foreach (var dbCategory in distinctDbCategories)
                {
                    domainCategories.Add(categoryMapper.MapFromDatabase(dbCategory));
                }
            }

            return(domainCategories);
        }