Ejemplo n.º 1
0
        public ActionResult Create(CreateFurnituresViewModel requestedViewModel)
        {
            if (ModelState.IsValid)
            {
                Furniture furniture = Mapper.Map <FurnitureFormViewModel, Furniture>(requestedViewModel.FurnitureForm);

                FurnitureService.Create(furniture);

                Image image = ImageService.Upload(requestedViewModel.ProfileImage, furniture);
                ImageService.Resize(image, FurnitureService.ImageSizes, furniture);

                FurnitureService.SetProfileImage(furniture, image);

                return(RedirectToAction("Update", new { id = furniture.FurnitureId }));
            }

            requestedViewModel.FurnitureForm.Designers = FurnitureService.GetDesigners().Select(designer => new SelectListItem
            {
                Text  = designer.FullName,
                Value = designer.DesignerId.ToString()
            });
            requestedViewModel.FurnitureForm.Types = FurnitureService.GetTypes().Select(furnitureType => new SelectListItem
            {
                Text  = furnitureType.Name,
                Value = furnitureType.FurnitureTypeId.ToString()
            });

            return(View(requestedViewModel));
        }