Beispiel #1
0
        public ActionResult EditFTLocation(int id)
        {
            FoodtruckVM model;

            using (Db db = new Db())
            {
                FoodtruckDTO dto = db.Foodtrucks.Find(id);

                if (dto == null)
                {
                    return(Content("The FT location does not exist."));
                }

                model = new FoodtruckVM(dto);
            }

            return(View(model));
        }
Beispiel #2
0
        public ActionResult AddFTLocation(FoodtruckVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (Db db = new Db())
            {
                // Declare PagesDTO
                FoodtruckDTO dto = new FoodtruckDTO();

                if (db.Foodtrucks.Any(x => x.Day == model.Day))
                {
                    ModelState.AddModelError("", "This day is already taken!!");
                    return(View(model));
                }
                var day = UppercaseFirst(model.Day.Trim());
                if (!(day == "Monday" || day == "Tuesday" || day == "Wednesday" || day == "Thursday" || day == "Friday" || day == "Saturday" || day == "Sunday"))
                {
                    ModelState.AddModelError("", "Please insert correct day");
                    return(View(model));
                }
                else
                {
                    switch (day)
                    {
                    case "Monday":
                        dto.Sorting = 1;
                        break;

                    case "Tuesday":
                        dto.Sorting = 2;
                        break;

                    case "Wednesday":
                        dto.Sorting = 3;
                        break;

                    case "Thursday":
                        dto.Sorting = 4;
                        break;

                    case "Friday":
                        dto.Sorting = 5;
                        break;

                    case "Saturday":
                        dto.Sorting = 6;
                        break;

                    case "Sunday":
                        dto.Sorting = 7;
                        break;

                    default:
                        Console.WriteLine("Default case");
                        break;
                    }
                }
                dto.Day      = day;
                dto.Location = model.Location;

                db.Foodtrucks.Add(dto);
                db.SaveChanges();
            }

            TempData["Success"] = "You have added a new FT location.";

            return(RedirectToAction("AddFTLocation"));
        }
Beispiel #3
0
        public ActionResult AddFTLocation()
        {
            FoodtruckVM model = new FoodtruckVM();

            return(View(model));
        }
Beispiel #4
0
        public ActionResult EditFTLocation(FoodtruckVM model)
        {
            int id = model.Id;

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

            using (Db db = new Db())
            {
                // Declare PagesDTO
                FoodtruckDTO dto = db.Foodtrucks.Find(id);

                if (dto == null)
                {
                    ModelState.AddModelError("", "This day does not exist.");
                    return(View(model));
                }
                var day = UppercaseFirst(model.Day.Trim());

                switch (day)
                {
                case "Monday":
                    dto.Sorting = 1;
                    break;

                case "Tuesday":
                    dto.Sorting = 2;
                    break;

                case "Wednesday":
                    dto.Sorting = 3;
                    break;

                case "Thursday":
                    dto.Sorting = 4;
                    break;

                case "Friday":
                    dto.Sorting = 5;
                    break;

                case "Saturday":
                    dto.Sorting = 6;
                    break;

                case "Sunday":
                    dto.Sorting = 7;
                    break;

                default:
                    Console.WriteLine("Default case");
                    break;
                }


                dto.Location = model.Location;

                db.SaveChanges();
            }

            TempData["Success"] = "You have edited a FT location.";

            return(RedirectToAction("EditFTLocation"));
        }