Beispiel #1
0
        /// <summary>
        /// Post example
        /// </summary>
        /// <param name="startDateDecorator"></param>
        public SynchronizationData Post(DateTimeDecorator startDateDecorator)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Input data format is invalid.");
                return(null);
            }
            DateTime startDate = startDateDecorator.DateTime;
            var      data      = new SynchronizationData();

            context = Request.GetOwinContext().Get <ApplicationDbContext>();

            foodConsistencyTypeService = new FoodConsistencyTypeService(context);
            data.FoodConsistencyTypes  = foodConsistencyTypeService.Get(startDate).ToList();

            foodCategoryService = new FoodCategoryService(context);
            data.FoodCategories = foodCategoryService.Get(startDate).ToList();

            dishCategoryService = new DishCategoryService(context);
            data.DishCategories = dishCategoryService.Get(startDate).ToList();

            foodService = new FoodService(context);
            data.Food   = foodService.Get(startDate).ToList();

            dishService = new DishService(context);
            data.Dishes = dishService.Get(startDate).ToList();

            portionService = new PortionFoodService(context);
            data.Portions  = portionService.Get(startDate).ToList();

            return(data);
        }
Beispiel #2
0
        public ActionResult Create([Bind(Exclude = "image")] DishCategoryViewModel model, HttpPostedFileBase image)
        {
            if (image == null)
            {
                ModelState.AddModelError("Image", "Please, choose image.");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            ValidationResult valRes = DishCategoryService.Add(new Models.DatabaseModels.DishCategory
            {
                Name             = model.Name,
                DateModification = DateTime.Now,
                IsDeleted        = false,
                Image            = ImageEditor.GetResizedImage(image, IMAGE_WIDTH, IMAGE_HEIGHT),
            });

            if (!valRes.IsSuccess)
            {
                ModelState.AddModelError("", valRes.GetAllErrors());
                return(View(model));
            }
            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public ActionResult Delete(int id)
        {
            ValidationResult valRes = DishCategoryService.Remove(id);

            if (!valRes.IsSuccess)
            {
                return(View("Error"));
            }
            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public ActionResult Index()
        {
            IEnumerable <DishCategoryViewModel> model = DishCategoryService.Get()
                                                        .Select(dc => new DishCategoryViewModel
            {
                Id = dc.Id,
                DateModification = dc.DateModification,
                Image            = dc.Image,
                IsDeleted        = dc.IsDeleted,
                Name             = dc.Name,
            }).ToList();

            return(View(model));
        }
Beispiel #5
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Dish dish = DishService.Get(id.Value);
            //List<String> strings = new List<String>();
            SelectList list = new SelectList(DishCategoryService.Get(), "Id", "Name");

            list.First(i =>
            {
                // strings.Add(i.Text);
                return(i.Value == dish.IdDishCategory.ToString());
            }).Selected            = true;
            ViewBag.IdDishCategory = list;
            ViewBag.DishToView     = dish;

            return(View(dish.PortionFood));
        }
 public DishCategoriesController(DishCategoryService dishCategoryService)
 {
     _dishCategoryService = dishCategoryService;
 }
Beispiel #7
0
        public DishCategoryController()
        {
            Context = Request != null?Request.GetOwinContext().Get <ApplicationDbContext>() : ApplicationDbContext.Create();

            DishCategoryService = new DishCategoryService(Context);
        }
        protected override void Seed(ApplicationDbContext context)
        {
            var type1 = new FoodConsistencyType {
                Name = "Твердый"
            };
            var type2 = new FoodConsistencyType {
                Name = "Жидкий"
            };
            var foodConsistencyTypeService = new FoodConsistencyTypeService(context);

            foodConsistencyTypeService.Add(type1);
            foodConsistencyTypeService.Add(type2);

            var fakeFoodCategory = new FoodCategory
            {
                DateModification = DateTime.Now,
                Name             = "fake",
                Image            = new byte[] { 3, 3 }
            };
            var foodCategoryService = new FoodCategoryService(context);

            foodCategoryService.Add(fakeFoodCategory);

            var fakeDishCategory = new DishCategory
            {
                DateModification = DateTime.Now,
                Name             = "fake",
                Image            = new byte[] { 4 }
            };
            var dishCategoryService = new DishCategoryService(context);

            dishCategoryService.Add(fakeDishCategory);

            var fakeDish1 = new Dish
            {
                Name             = "fake1",
                DishCategory     = fakeDishCategory,
                TotalAmountWater = 1,
                TotalCarbs       = 1,
                TotalCcal        = 1,
                TotalFat         = 1,
                TotalProteins    = 1,
                TotalSugar       = 1
            };
            var fakeDish2 = new Dish
            {
                Name             = "fake2",
                DishCategory     = fakeDishCategory,
                TotalAmountWater = 2,
                TotalCarbs       = 2,
                TotalCcal        = 2,
                TotalFat         = 2,
                TotalProteins    = 2,
                TotalSugar       = 2,
                IsDeleted        = true
            };
            var fakeDish3 = new Dish
            {
                Name             = "fake3",
                DishCategory     = fakeDishCategory,
                TotalAmountWater = 3,
                TotalCarbs       = 3,
                TotalCcal        = 3,
                TotalFat         = 3,
                TotalProteins    = 3,
                TotalSugar       = 3
            };
            var fakeDish4 = new Dish
            {
                Name             = "fake4",
                DishCategory     = fakeDishCategory,
                TotalAmountWater = 4,
                TotalCarbs       = 4,
                TotalCcal        = 4,
                TotalFat         = 4,
                TotalProteins    = 4,
                TotalSugar       = 4
            };
            var fakeDish5 = new Dish
            {
                Name             = "fake5",
                DishCategory     = fakeDishCategory,
                TotalAmountWater = 5,
                TotalCarbs       = 5,
                TotalCcal        = 5,
                TotalFat         = 5,
                TotalProteins    = 5,
                TotalSugar       = 5
            };
            var dishService = new DishService(context);

            dishService.Add(fakeDish1);
            dishService.Add(fakeDish2);
            dishService.Add(fakeDish3);
            dishService.Add(fakeDish4);
            dishService.Add(fakeDish5);

            var fakeFood1 = new Food
            {
                Name                = "fake1",
                FoodCategory        = fakeFoodCategory,
                FoodConsistencyType = type1,
                Image               = new byte[] { 1 },
                AmountOfWater       = 1,
                Carbs               = 1,
                Ccal                = 1,
                Fat      = 1,
                Proteins = 1,
                Sugar    = 1
            };
            var fakeFood2 = new Food
            {
                Name                = "fake2",
                FoodCategory        = fakeFoodCategory,
                FoodConsistencyType = type1,
                Image               = new byte[] { 3 },
                AmountOfWater       = 2,
                Carbs               = 2,
                Ccal                = 2,
                Fat      = 2,
                Proteins = 2,
                Sugar    = 2
            };
            var foodService = new FoodService(context);

            foodService.Add(fakeFood1);
            foodService.Add(fakeFood2);

            var fakePortion1 = new PortionFood
            {
                Dish   = fakeDish1,
                Food   = fakeFood1,
                Amount = 3
            };
            var fakePortion2 = new PortionFood
            {
                Dish   = fakeDish1,
                Food   = fakeFood2,
                Amount = 5
            };
            var portionFoodService = new PortionFoodService(context);

            portionFoodService.Add(fakePortion1);
            portionFoodService.Add(fakePortion2);

            var fakeActivityType = new UserActivityType()
            {
                Description = "fake",
                Name        = "fake"
            };
            var fakeActivityTypeService = new UserActivityTypeService(context);

            fakeActivityTypeService.Add(fakeActivityType);

            RoleManager <IdentityRole> roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            ApplicationUserManager     userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(context));

            roleManager.Create(new IdentityRole("Admin"));
            roleManager.Create(new IdentityRole("User"));
            string adminEmail = "*****@*****.**";

            if (userManager.Create(new ApplicationUser()
            {
                Email = adminEmail, UserName = "******"
            }, "bsuirhealthproject").Succeeded == true)
            {
                ApplicationUser user = userManager.FindByEmail(adminEmail);
                userManager.AddToRole(user.Id, "Admin");
                userManager.AddToRole(user.Id, "User");
                var userService = new UserService(context);
                userService.Add(new User
                {
                    DateOfBirth      = DateTime.Now,
                    FirstName        = "fake",
                    IdActivityType   = fakeActivityType.Id,
                    IdUserCredential = user.Id,
                    LastName         = "fake",
                    Sex = false
                });
            }
        }