Пример #1
0
        public async Task <IActionResult> CreateMeal(Meal meal)
        {
            if (meal == null)
            {
                return(BadRequest());
            }
            await MealRepository.CreateMeal(meal);

            return(Accepted());
        }
Пример #2
0
 public IActionResult NewMeal(Meal Meal)
 {
     Meal.Cook = UserRepository.Users.Where(e => e.Id == User.FindFirstValue(ClaimTypes.NameIdentifier)).FirstOrDefault();
     if (MealRepository.CreateMeal(Meal))
     {
         return(Redirect("/Meal"));
     }
     else
     {
         ModelState.AddModelError("Date", "A meal is already planned on this day");
         return(View(Meal));
     }
 }
Пример #3
0
 public IActionResult Create(AllMeals allMeals)
 {
     if (ModelState.IsValid)
     {
         mealRepository.CreateMeal(allMeals);
         TempData["message"] = $"{allMeals.Name} has been saved";
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View(allMeals));
     }
 }
Пример #4
0
        public async Task <ICreateMealResponse> CreateMeal(ICreateMealRequest createMealRequest)
        {
            try
            {
                Meal meal = await _mealRepository.CreateMeal(createMealRequest.Name, createMealRequest.Description,
                                                             createMealRequest.Price, createMealRequest.StartDate, createMealRequest.EndDate,
                                                             createMealRequest.RestaurantId);

                return(new CreateMealResponse(meal));
            }
            catch (Exception ex)
            {
                _logger.Log(ex);
                return(new CreateMealResponse(CreateMealEnum.Exception));
            }
        }
Пример #5
0
        public async Task ChooseMeals(Guid id, IEnumerable <Dish> dishes)
        {
            await EnsureGuestExists(id);

            var meals = await GetMeals(id);

            var toDelete = meals.Where(w => !dishes.Any(a => a.Id == w.DishId));
            var toCreate = dishes.Where(w => !meals.Any(a => a.DishId == w.Id)).Select(s => new Meal {
                GuestId = id, DishId = s.Id
            });

            foreach (var meal in toDelete)
            {
                await _mealRepository.DeleteMeal(meal.Id);
            }

            foreach (var meal in toCreate)
            {
                await _mealRepository.CreateMeal(meal);
            }
        }
Пример #6
0
        public InfoScreenMutation(
            IAdminRepository admins,
            ILunchplanRepository lunchplans,
            IMealRepository meals,
            IMessageRepository messages
            )
        {
            Name = "Mutation";

            FieldAsync <BooleanGraphType>(
                "createAdmin",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <AdminInputType> > {
                Name = "admin"
            }
                    ),
                resolve: async ctx =>
            {
                var input = ctx.GetArgument <Dictionary <string, object> >("admin");
                var admin = new DAL.Entity.Admin
                {
                    Username = (string)input["username"]
                };
                admin.SetPassword((string)input["password"]);

                return(await admins.CreateAdmin(admin));
            }
                );

            FieldAsync <BooleanGraphType>(
                "updateAdmin",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <AdminInputType> > {
                Name = "admin"
            }
                    ),
                resolve: async ctx =>
            {
                var input = ctx.GetArgument <Dictionary <string, object> >("admin");
                var admin = new DAL.Entity.Admin
                {
                    Username = (string)input["username"]
                };
                admin.SetPassword((string)input["password"]);

                return(await admins.UpdateAdmin(admin));
            }
                );

            FieldAsync <BooleanGraphType>(
                "deleteAdmin",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "admin"
            }
                    ),
                resolve: async ctx =>
            {
                if (ctx.HasArgument("admin"))
                {
                    return(await admins.DeleteAdmin(ctx.GetArgument <string>("admin")));
                }
                return(false);
            });

            FieldAsync <BooleanGraphType>(
                "saveLunchplan",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <LunchplanInputType> > {
                Name = "lunchplan"
            }
                    ),
                resolve: async ctx =>
            {
                var arg      = ctx.GetArgument <Dictionary <string, object> >("lunchplan");
                var week     = (int)arg["week"];
                var mp       = (Dictionary <string, object>)arg["mealplan"];
                var mealplan = new Dictionary <Weekday, int>();
                foreach (var(key, val) in mp)
                {
                    mealplan[Enum.Parse <Weekday>(key, true)] = (int)val;
                }

                var lunchplan = new Lunchplan
                {
                    WeekNumber = week,
                    Mealplan   = mealplan
                };

                return(await lunchplans.SaveLunchplan(lunchplan));
            }
                );

            FieldAsync <BooleanGraphType>(
                "createMeal",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <MealInputType> > {
                Name = "meal"
            }
                    ),
                resolve: async ctx =>
            {
                var meal = ctx.GetArgument <Meal>("meal");
                return(await meals.CreateMeal(meal));
            }
                );

            FieldAsync <BooleanGraphType>(
                "createMessage",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <MessageInputType> > {
                Name = "message"
            }
                    ),
                resolve: async ctx =>
            {
                var message       = ctx.GetArgument <Message>("message");
                message.Date      = DateTime.Now;
                message.CreatedBy = ctx.UserContext.As <InfoScreenUserContext>().AdminId;
                return(await messages.CreateMessage(message));
            }
                );
        }
Пример #7
0
 public void CreateMeal(Meal meal, string userId)
 {
     _mealRepository.CreateMeal(meal, userId);
 }
Пример #8
0
 public void CreateMeal(Meal meal)
 {
     mealRepository.CreateMeal(meal);
 }
Пример #9
0
        public async Task <MealDto> CreateMeal(MealDto mealDto)
        {
            var result = await _mealRepository.CreateMeal(mealDto);

            return(result);
        }