Esempio n. 1
0
        internal bool AddGeneralListItem(SRL_Ingredient ingredient, int listId)
        {
            using (DataContext)
            {
                try
                {
                    int count = (from p in DataContext.GeneralListDetails
                                 where p.LIST_ID == listId && p.ITEM_NAME == ingredient.FoodName
                                 select p).Count();

                    if (count == 0)
                    {
                        GeneralListDetail generalListDetail = new GeneralListDetail
                        {
                            ITEM_NAME           = ingredient.FoodName,
                            LIST_ID             = listId,
                            COMPLETE_QUANTITY   = ingredient.CompleteValue,
                            MEASUREMENT_UNIT_ID = ingredient.MeasurementUnitId,
                            MEASUREMENT_UNIT    = ingredient.MeasurementUnitName
                        };
                        DataContext.GeneralListDetails.InsertOnSubmit(generalListDetail);
                    }
                    else
                    {
                        GeneralListDetail generalListDetail = (from p in DataContext.GeneralListDetails
                                                               where
                                                               p.LIST_ID == listId &&
                                                               p.ITEM_NAME == ingredient.FoodName
                                                               select p).Single();

                        generalListDetail.COMPLETE_QUANTITY   = ingredient.CompleteValue;
                        generalListDetail.MEASUREMENT_UNIT_ID = ingredient.MeasurementUnitId;
                        generalListDetail.MEASUREMENT_UNIT    = ingredient.MeasurementUnitName;
                    }
                    DataContext.SubmitChanges();

                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }
Esempio n. 2
0
        internal bool DeleteGeneralListItem(int ingredientId)
        {
            using (DataContext)
            {
                try
                {
                    GeneralListDetail generalListDetail = (from p in DataContext.GeneralListDetails
                                                           where p.ID == ingredientId
                                                           select p).Single();

                    DataContext.GeneralListDetails.DeleteOnSubmit(generalListDetail);
                    DataContext.SubmitChanges();

                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }