Пример #1
0
        public ActionResult New(DishVM newDish)
        {
            //Check if the model is valid ( newDish depending on property validations
            if (ModelState.IsValid)
            {
                //Get the current user
                var currentUser = UserContext.Current.CurrentUser;
                var user = UserSvc.GetUserById(currentUser.id);

                var dishType = DishTypeSvc.GetDishTypeById(newDish.SelectedDishType);

                //Create a new dish object instance.
                var dish = new Dish()
                {
                    Availability = DateTime.Now.AddMonths(1),
                    Description = newDish.Description,
                    Dishtype = dishType,
                    Food = newDish.Food,
                    Name = newDish.Name,
                    Price = newDish.Price,
                    Seller = new NestedUser()
                    {
                        _id = user._id,
                        Email = user.Email,
                        Username = user.Username
                    }
                };

                //Add the creation to the database
              var createdDish =  DishSvc.CreateADish(dish);

                //Check for picture file
              var filename = ImageSvc.SaveImage(newDish.Picture, createdDish._id.ToString(), Server.MapPath(ConfigurationManager.AppSettings["dishdirpicture"]));
               createdDish.Picture = filename;

                //Update the above dish with generated picture filename.
              DishSvc.UpdateDish(createdDish);

                // notification.
                UserContext.Current.Notify = " Dish Added !";
                UserContext.Current.NotifyType = notificationType.success.Value();

                return RedirectToAction("Index", "Account");

            }

            return View(newDish);
        }
Пример #2
0
        //
        // GET: /Dish/New
        public ActionResult New()
        {
            // DishVM and dish types  initialisations.
            var dishtoAdd = new DishVM();
            dishtoAdd.DishTypes = DishTypeSvc.GetDishTypes();

            return View(dishtoAdd);
        }