コード例 #1
0
 public IngredientDetail GetIngredientbyId(int id)
 {
     using (var context = new CookbookContext())
     {
         var entity =
             context
             .Ingredients
             .Single(e => e.ID == id && e.AuthorID == userId);
         var ingredientDetail =
             new IngredientDetail
         {
             ID           = entity.ID,
             Name         = entity.Name,
             Description  = entity.Description,
             DateCreated  = entity.DateCreated,
             DateModified = entity.DateModified,
             Amount       = entity.Amount,
             Unit         = entity.Unit,
             TemplateId   = entity.TemplateId,
         };
         var TemplateName = context.Larders
                            .SingleOrDefault(l => l.AuthorID == userId && l.ID == entity.TemplateId);
         if (TemplateName != null)
         {
             ingredientDetail.TemplateName = TemplateName.Name.ToString();
         }
         return(ingredientDetail);
     }
 }
コード例 #2
0
        public int CreateRecipe(RecipeCreate model)
        {
            using (var context = new CookbookContext())
            {
                var season = new Season()
                {
                    AuthorID = userId,
                    Summer = model.Season.Summer,
                    Fall = model.Season.Fall,
                    Winter = model.Season.Winter,
                    Spring = model.Season.Spring
                };

                context.Seasons.Add(season);
                context.SaveChanges();

                var entity = new Recipe()
                {
                    AuthorID = userId,
                    Name = model.Name,
                    SeasonID = season.ID,
                    Description = model.Description,
                    DateCreated = DateTimeOffset.UtcNow,
                };

                context.Recipes.Add(entity);
                context.SaveChanges();
                return entity.ID;
            }
        }
コード例 #3
0
        public RecipeDetail GetRecipebyId(int id)
        {
            using (var context = new CookbookContext())
            {
                var entity =
                    context
                           .Recipes
                           .Single(e => e.ID == id && e.AuthorID == userId);
                var ingredients =
                          context
                                 .Ingredients
                                 .Where(i => i.AuthorID == userId && i.LarderId == id)
                                 .Select(
                                     i =>
                                         new IngredientListItem
                                         {
                                             ID = i.ID,
                                             Amount = i.Amount,
                                             Unit = i.Unit,
                                             Name = i.Name,
                                             Description = i.Description
                                         }
                              ).ToList();
                var actions =
                      context
                             .Actions
                             .Where(a => a.AuthorID == userId && a.LarderId == id)
                             .Select(
                                 a =>
                                     new ActionListItem
                                     {
                                         ID = a.ID,
                                         Description = a.Description
                                     }
                          ).ToList();
                var platings = GetPlatingsByRecipeId(id);

                return
                    new RecipeDetail
                    {
                        ID = entity.ID,
                        Name = entity.Name,
                        Description = entity.Description,
                        Ingredients = new IngredientList { LarderId=entity.ID, Ingredients = ingredients },
                        Actions = new ActionList { LarderId=entity.ID, Directions = actions },
                        Seasons = entity.Season.GetSeasons(),
                        DateCreated = entity.DateCreated,
                        DateModified = entity.DateModified,
                        Platings = platings
                    };
            }
        }
コード例 #4
0
ファイル: myLarderService.cs プロジェクト: pfesenmeier/Larder
        public bool DeleteLarder(int id)
        {
            using (var context = new CookbookContext())
            {
                var entity =
                    context
                    .Larders
                    .Single(e => e.ID == id && e.AuthorID == userId);
                context.Larders.Remove(entity);

                return(context.SaveChanges() == 1);
            }
        }
コード例 #5
0
ファイル: ActionService.cs プロジェクト: pfesenmeier/Larder
        public bool UpdateAction(ActionEdit model)
        {
            using (var context = new CookbookContext())
            {
                var entity =
                    context
                    .Actions
                    .Single(e => e.ID == model.ID && e.AuthorID == userId);
                entity.Description = model.Description;

                return(context.SaveChanges() == 1);
            }
        }
コード例 #6
0
ファイル: ActionService.cs プロジェクト: pfesenmeier/Larder
        public bool CreateAction(ActionCreate model)
        {
            var entity = new Data.Models.Action()
            {
                AuthorID    = userId,
                Description = model.Description,
                LarderId    = model.LarderID
            };

            using (var context = new CookbookContext())
            {
                context.Actions.Add(entity);
                return(context.SaveChanges() == 1);
            }
        }
コード例 #7
0
ファイル: LarderService.cs プロジェクト: pfesenmeier/Larder
        public bool UpdateLarder(LarderEdit model)
        {
            using (var context = new CookbookContext())
            {
                var entity =
                    context
                    .Larders
                    .Single(e => e.ID == model.ID && e.AuthorID == userId);
                entity.Name         = model.Name;
                entity.Description  = model.Description;
                entity.DateModified = DateTimeOffset.UtcNow;

                return(context.SaveChanges() == 1);
            }
        }
コード例 #8
0
 public List<RecipeListItem> GetRecipesByLarderId(int id)
 {
     using (var context = new CookbookContext())
     {
         return context
                         .Recipes
                         .Where(x => x.Ingredients.Any(i => i.TemplateId == id))
                         .Select(
                                 r =>
                                 new RecipeListItem()
                                 {
                                     ID = r.ID,
                                     Name = r.Name,
                                 }).ToList();
     }
 }
コード例 #9
0
ファイル: myLarderService.cs プロジェクト: pfesenmeier/Larder
        public bool CreateLarder(LarderCreate model)
        {
            var entity = new LarderModel()
            {
                AuthorID    = userId,
                Name        = model.Name,
                Description = model.Description,
                DateCreated = DateTimeOffset.UtcNow,
            };

            using (var context = new CookbookContext())
            {
                context.Larders.Add(entity);
                return(context.SaveChanges() == 1);
            }
        }
コード例 #10
0
ファイル: ActionService.cs プロジェクト: pfesenmeier/Larder
 public ActionDetail GetActionById(int id)
 {
     using (var context = new CookbookContext())
     {
         var entity =
             context
             .Actions
             .Single(e => e.ID == id && e.AuthorID == userId);
         return
             (new ActionDetail
         {
             ID = entity.ID,
             Description = entity.Description
         });
     }
 }
コード例 #11
0
        public void PopulateAssignedMealTypeData(CookbookContext context, Recipe recipe)
        {
            var allMealTypes    = context.MealTypes;
            var recipeMealTypes = new HashSet <int>(
                recipe.RecipeAssignments.Select(m => m.MealTypeID));

            AssignedMealTypeDataList = new List <AssignedMealTypeData>();
            foreach (var mealType in allMealTypes)
            {
                AssignedMealTypeDataList.Add(new AssignedMealTypeData
                {
                    MealTypeID = mealType.ID,
                    Name       = mealType.Name,
                    Assigned   = recipeMealTypes.Contains(mealType.ID)
                });
            }
        }
コード例 #12
0
        public bool UpdateIngredient(IngredientEdit model)
        {
            using (var context = new CookbookContext())
            {
                var entity =
                    context
                    .Ingredients
                    .Single(e => e.ID == model.ID && e.AuthorID == userId);
                entity.Name         = model.Name;
                entity.Description  = model.Description;
                entity.Amount       = model.Amount;
                entity.Unit         = model.Unit;
                entity.DateModified = DateTimeOffset.UtcNow;

                return(context.SaveChanges() == 1);
            }
        }
コード例 #13
0
        public List<PlatingListItem> GetPlatingsByRecipeId(int id)
        {

            using (var context = new CookbookContext())
            {
                return context
                              .Platings
                              .Where(x => x.RecipePlatings.Any(rp => rp.RecipeID == id))
                              .Select(
                                  p =>
                                      new PlatingListItem()
                                      {
                                          ID = p.ID,
                                          Name = p.Name
                                      })
                              .ToList();
            }
        }
コード例 #14
0
        public List<RecipeListItem> GetRecipesByPlatingId(int id)
        {

            using (var context = new CookbookContext())
            {
              return context
                            .Recipes
                            .Where(x => x.RecipePlatings.Any(rp => rp.PlatingID == id))
                            .Select(
                                r =>
                                    new RecipeListItem()
                                    {
                                        ID = r.ID,
                                        Name = r.Name
                                    })
                            .ToList();
            }
        }
コード例 #15
0
        public bool UpdateRecipe(RecipeEdit model)
        {
            using (var context = new CookbookContext())
            {
                var entity =
                    context
                           .Recipes
                           .Single(e => e.ID == model.ID && e.AuthorID == userId);
                entity.Name = model.Name;
                entity.Description = model.Description;
                entity.DateModified = DateTimeOffset.UtcNow;
                if (model.Season.Fall) { entity.Season.Fall = true;} else { entity.Season.Fall = false; }
                if (model.Season.Spring) { entity.Season.Spring = true;} else { entity.Season.Spring = false; }
                if (model.Season.Summer) { entity.Season.Summer = true;} else { entity.Season.Summer = false; }
                if (model.Season.Winter) { entity.Season.Winter = true;} else { entity.Season.Winter = false; }

                return context.SaveChanges() != 0;
            }
        }
コード例 #16
0
 public PlatingDetail GetPlatingbyId(int id)
 {
     using (var context = new CookbookContext())
     {
         var query =
             context
             .Platings
             .Single(e => e.AuthorID == userId && e.ID == id);
         return(new PlatingDetail()
         {
             ID = query.ID,
             Name = query.Name,
             Description = query.Description,
             DateCreated = query.DateCreated,
             DateModified = query.DateModified,
             Recipes = GetRecipesByPlatingId(id)
         });
     }
 }
コード例 #17
0
        public bool CreateIngredient(IngredientCreate model)
        {
            var entity = new Ingredient()
            {
                AuthorID    = userId,
                Name        = model.Name,
                Description = model.Description,
                DateCreated = DateTimeOffset.UtcNow,
                Amount      = model.Amount,
                Unit        = model.Unit,
                LarderId    = model.LarderId,
            };

            using (var context = new CookbookContext())
            {
                context.Ingredients.Add(entity);
                return(context.SaveChanges() == 1);
            }
        }
コード例 #18
0
 private List <RecipeListItem> GetRecipesByPlatingId(int id)
 {
     using (var context = new CookbookContext())
     {
         return(context
                .RecipePlatings
                .Where(rp => rp.PlatingID == id)
                .Select(rp =>
                        new RecipeListItem()
         {
             ID = rp.RecipeID,
             Name = context
                    .Recipes
                    .FirstOrDefault(r => r.ID == rp.RecipeID)
                    .Name
         })
                .ToList());
     }
 }
コード例 #19
0
ファイル: ActionService.cs プロジェクト: pfesenmeier/Larder
 public IEnumerable <ActionListItem> GetActions()
 {
     using (var context = new CookbookContext())
     {
         var query =
             context
             .Actions
             .Where(e => e.AuthorID == userId)
             .Select(
                 e =>
                 new ActionListItem
         {
             ID          = e.ID,
             Description = e.Description
         }
                 );
         return(query.ToArray());
     }
 }
コード例 #20
0
 public IEnumerable <PlatingListItem> GetPlatings()
 {
     using (var context = new CookbookContext())
     {
         var query =
             context
             .Platings
             .Where(e => e.AuthorID == userId)
             .Select(
                 e =>
                 new PlatingListItem
         {
             ID          = e.ID,
             Name        = e.Name,
             Description = e.Description,
         }
                 );
         return(query.ToArray());
     }
 }
コード例 #21
0
ファイル: myLarderService.cs プロジェクト: pfesenmeier/Larder
 public IEnumerable <LarderListItem> GetLarders()
 {
     using (var context = new CookbookContext())
     {
         var query =
             context
             .Larders
             .Where(e => e.AuthorID == userId)
             .Select(
                 e =>
                 new LarderListItem
         {
             ID          = e.ID,
             Name        = e.Name,
             Description = e.Description,
             Season      = e.Season
         }
                 );
         return(query.ToArray());
     }
 }
コード例 #22
0
ファイル: myLarderService.cs プロジェクト: pfesenmeier/Larder
        public LarderDetail GetLarderbyId(int id)
        {
            using (var context = new CookbookContext())
            {
                var entity =
                    context
                    .Larders
                    .Single(e => e.ID == id && e.AuthorID == userId);
                var ingredients =
                    context
                    .Ingredients
                    .Where(i => i.AuthorID == userId && i.LarderId == id)
                    .Select(
                        i =>
                        new IngredientListItem
                {
                    ID          = i.ID,
                    Amount      = i.Amount,
                    Unit        = i.Unit,
                    Name        = i.Name,
                    Description = i.Description
                }
                        );
                var actions =
                    context
                    .Actions
                    .Where(a => a.AuthorID == userId && a.LarderId == id)
                    return
                        (new LarderDetail
                {
                    ID = entity.ID,
                    Name = entity.Name,
                    Description = entity.Description,

                    Seasons = entity.Season.GetSeasons(),
                    DateCreated = entity.DateCreated,
                    DateModified = entity.DateModified
                });
            }
        }
コード例 #23
0
ファイル: LarderService.cs プロジェクト: pfesenmeier/Larder
        public int CreateLarder(LarderCreate model)
        {
            using (var context = new CookbookContext())
            {
                var season = new Season();
                if (model.Season == null)
                {
                    season.AuthorID = userId;
                    season.Summer   = false;
                    season.Fall     = false;
                    season.Winter   = false;
                    season.Spring   = false;
                }
                else
                {
                    season.AuthorID = userId;
                    season.Summer   = model.Season.Summer;
                    season.Fall     = model.Season.Fall;
                    season.Winter   = model.Season.Winter;
                    season.Spring   = model.Season.Spring;
                };

                context.Seasons.Add(season);
                context.SaveChanges();

                var entity = new LarderModel()
                {
                    AuthorID    = userId,
                    Name        = model.Name,
                    SeasonID    = season.ID,
                    Description = model.Description,
                    DateCreated = DateTimeOffset.UtcNow,
                };

                context.Larders.Add(entity);
                context.SaveChanges();
                return(entity.ID);
            }
        }
コード例 #24
0
 public IEnumerable <IngredientListItem> GetIngredients()
 {
     using (var context = new CookbookContext())
     {
         var query =
             context
             .Ingredients
             .Where(e => e.AuthorID == userId)
             .Select(
                 e =>
                 new IngredientListItem
         {
             ID          = e.ID,
             Name        = e.Name,
             Description = e.Description,
             Amount      = e.Amount,
             Unit        = e.Unit
         }
                 );
         return(query.ToArray());
     }
 }
コード例 #25
0
 public bool AddPlating(PlatingAddList model)
 {
     using (var context = new CookbookContext())
     {
         var entities = context.RecipePlatings.Where(e => e.RecipeID == model.RecipeId);
         foreach (var entity in entities)
         {
             context.RecipePlatings.Remove(entity);
         }
         foreach (var plating in model.Platings)
         {
             if (plating.IsIncluded == true)
             {
                 context.Set <RecipePlating>().Add(new RecipePlating
                 {
                     PlatingID = plating.ID,
                     RecipeID  = model.RecipeId
                 });
             }
         }
         return(context.SaveChanges() != -1);
     }
 }
コード例 #26
0
        public void UpdateRecipeMealTypes(CookbookContext context, string[] selectedMealTypes, Recipe recipeToUpdate)
        {
            if (selectedMealTypes == null)
            {
                recipeToUpdate.RecipeAssignments = new List <RecipeAssignment>();
                return;
            }

            var selectedMealTypesHS = new HashSet <string>(selectedMealTypes);
            var recipeMealTypes     = new HashSet <int>(recipeToUpdate.RecipeAssignments.Select(r => r.Recipe.RecipeID));

            foreach (var mealType in context.MealTypes)
            {
                if (!selectedMealTypesHS.Contains(mealType.ID.ToString()))
                {
                    if (!recipeMealTypes.Contains(mealType.ID))
                    {
                        recipeToUpdate.RecipeAssignments.Add(
                            new RecipeAssignment
                        {
                            RecipeID   = recipeToUpdate.RecipeID,
                            MealTypeID = mealType.ID
                        });
                    }
                }
                else
                {
                    if (recipeMealTypes.Contains(mealType.ID))
                    {
                        RecipeAssignment mealToRemove = recipeToUpdate
                                                        .RecipeAssignments
                                                        .SingleOrDefault(r => r.MealTypeID == mealType.ID);
                        context.Remove(mealToRemove);
                    }
                }
            }
        }
コード例 #27
0
 public IngredientRepository(CookbookContext cookbookContext)
 {
     _cookbookContext = cookbookContext;
 }
コード例 #28
0
 public KomentarService(CookbookContext context, IMapper mapper) : base(context, mapper)
 {
 }
コード例 #29
0
 public BaseService(CookbookContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
コード例 #30
0
 public PreporukaService(CookbookContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }