public string AddToMissingList(int userId, string item, int quantity)
        {
            try
            {
                int listId = BusinessFacade.Instance.AddMissingList(userId);

                Food food = BusinessFacade.Instance.GetFood(item);
                if (food == null)
                {
                    BusinessFacade.Instance.SaveFood(new Food
                    {
                        FoodName       = item,
                        FoodCategoryId = 0
                    });
                }

                MissingListDetail missingListDetail = BusinessFacade.Instance.AddMissingListItem(item, quantity, listId);
                string            result            = JsonSerializer <MissingListDetail>(missingListDetail);
                return(result);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 2
0
 internal void UpdateMissingListItem(int id, int quantity)
 {
     using (DataContext)
     {
         MissingListDetail missingListDetail = DataContext.MissingListDetails.SingleOrDefault(p => p.ID == id);
         if (missingListDetail != null)
         {
             missingListDetail.QUANTITY = quantity;
             DataContext.SubmitChanges();
         }
     }
 }
Exemplo n.º 3
0
        internal void AddListItem(string name, int quantity, int measureUnit, int userId)
        {
            int missingListId;

            using (DataContext)
            {
                MissingList missingList = DataContext.MissingLists.SingleOrDefault(p => p.CREATED_BY == userId && p.ACTIVE.HasValue ? p.ACTIVE.Value : false);

                if (missingList != null)
                {
                    missingListId = missingList.ID;

                    MissingListDetail missingListDetail = null;

                    Food food = DataContext.Foods.SingleOrDefault(p => p.FoodName == name);

                    if (food == null)
                    {
                        food = new Food
                        {
                            FoodName  = name,
                            CreatedBy = userId,
                        };
                        new AdminDA().SaveFood(food);
                        food = DataContext.Foods.SingleOrDefault(p => p.FoodName == name);
                    }

                    missingListDetail = DataContext.MissingListDetails.SingleOrDefault(p => p.LIST_ID == missingListId && p.FOOD_ID == food.FoodId);

                    if (missingListDetail != null)
                    {
                        missingListDetail.QUANTITY = quantity;
                    }
                    else
                    {
                        missingListDetail = new MissingListDetail
                        {
                            FOOD_ID             = food.FoodId,
                            LIST_ID             = missingListId,
                            QUANTITY            = quantity,
                            MEASUREMENT_UNIT_ID = measureUnit
                        };
                        DataContext.MissingListDetails.Add(missingListDetail);
                        //DataContext.MissingListDetails.InsertOnSubmit(missingListDetail);
                    }
                }

                DataContext.SaveChanges();
                //DataContext.SubmitChanges();
            }
        }
Exemplo n.º 4
0
        internal void RemoveItemFromShoppingList(int userId, int foodId)
        {
            MissingList missingListRow = DataContext.MissingLists.SingleOrDefault(x => x.CREATED_BY == userId);

            if (missingListRow != null)
            {
                MissingListDetail missingListDetailsRow = DataContext.MissingListDetails.SingleOrDefault(x => x.LIST_ID == missingListRow.ID && x.FOOD_ID == foodId);
                if (missingListDetailsRow != null)
                {
                    DataContext.MissingListDetails.Remove(missingListDetailsRow);
                    DataContext.SaveChanges();
                }
            }
        }
Exemplo n.º 5
0
        internal void RemoveItemFromShoppingList(int userId, int foodId)
        {
            MissingList missingListRow = DataContext.MissingLists.SingleOrDefault(x => x.CREATED_BY == userId);

            if (missingListRow != null)
            {
                MissingListDetail missingListDetailsRow = DataContext.MissingListDetails.SingleOrDefault(x => x.LIST_ID == missingListRow.ID && x.FOOD_ID == foodId);
                if (missingListDetailsRow != null)
                {
                    DataContext.MissingListDetails.DeleteOnSubmit(missingListDetailsRow);
                    DataContext.SubmitChanges(ConflictMode.FailOnFirstConflict);
                }
            }
        }
Exemplo n.º 6
0
        internal void DeleteListItem(int id)
        {
            using (DataContext)
            {
                int listId = 0;
                MissingListDetail missingListDetail = DataContext.MissingListDetails.SingleOrDefault(p => p.ID == id);
                if (missingListDetail != null)
                {
                    listId = missingListDetail.LIST_ID;
                    DataContext.MissingListDetails.DeleteOnSubmit(missingListDetail);
                    DataContext.SubmitChanges();
                }

                if (!DataContext.MissingListDetails.Any())
                {
                    DeleteList(listId);
                }
            }
        }