コード例 #1
0
        //
        // GET: /Dish/Edit/id
        public ActionResult Edit(string id)
        {
            //Get the dish to be edited.
            var dishToEdit = DishSvc.GetDishById(id);

            //generate ( wrong : the editDishViewmodel has to be mapped from a service layer dto..) the edit dish object from entity object.
            var model = new EditDishVM()
            {
                id= dishToEdit._id.ToString(),
                Availability = dishToEdit.Availability,
                Description = dishToEdit.Description,
                Food = dishToEdit.Food,
                SelectedDishType = dishToEdit.Dishtype._id.ToString(),
                Name = dishToEdit.Name,
                Price = dishToEdit.Price,

            };

            // Dish types  initialisations.
            model.DishTypes = DishTypeSvc.GetDishTypes();
            return View(model);
        }
コード例 #2
0
        public ActionResult Edit(EditDishVM editDishViewModel)
        {
            try
            {
                var currentUser = UserContext.Current.CurrentUser;
                var currentDish = DishSvc.GetDishById(editDishViewModel.id);
                 var dishType = DishTypeSvc.GetDishTypeById(editDishViewModel.SelectedDishType);
                var user = UserSvc.GetUserById(currentUser.id);

                var editedDish = new Dish()
                {
                    _id = currentDish._id,
                    Availability = editDishViewModel.Availability,
                    Description = editDishViewModel.Description,
                    Dishtype = dishType,
                    Food = editDishViewModel.Food,
                    Name = editDishViewModel.Name,
                    Price = editDishViewModel.Price,
                    Seller = new NestedUser()
                    {
                        _id = user._id,
                        Email = user.Email,
                        Username = user.Username
                    },
                    Picture = currentDish.Picture
                };

                var filename = ImageSvc.UpdateImage(editDishViewModel.Picture, currentDish._id.ToString(), Server.MapPath(ConfigurationManager.AppSettings["dishdirpicture"]), currentDish.Picture);

                if(filename != null)
                    editedDish.Picture = filename;

                DishSvc.UpdateDish(editedDish);

                // TODO: Add update logic here

                return RedirectToAction("Index", "Account");
            }
            catch
            {
                return RedirectToAction("Index", "Account");
            }
        }