예제 #1
0
        public ActionResult Edit([Bind(Include = "Form")] ClothCreateViewModel model)
        {
            _clotherService.UpdateCloth(new Cloth
            {
                Id          = model.Form.Id,
                Name        = model.Form.Name,
                ClothTypeId = model.Form.ClothTypeId,
                BrandId     = model.Form.BrandId
            });

            return(RedirectToAction("Index"));
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "Form")] ClothCreateViewModel model, HttpPostedFileBase[] uploadImages)
        {
            //Move mapping and add images to ClotherService

            var pictures = _clotherService.GetPicturesList(uploadImages);

            var cloth = Mapper.Map <ClothCreateForm, Cloth>(model.Form);

            cloth.Pictures = pictures;

            _clotherService.CreateCloth(cloth);

            return(RedirectToAction("Index"));
        }
예제 #3
0
        private string ProcessUploadedFile(ClothCreateViewModel model)
        {
            string uniquieFileName = null;

            if (model.Photo != null)
            {
                string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                uniquieFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                string filePath = Path.Combine(uploadsFolder, uniquieFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.Photo.CopyTo(fileStream);
                }
            }

            return(uniquieFileName);
        }
예제 #4
0
        public IActionResult Create(ClothCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniquieFileName = ProcessUploadedFile(model);
                Cloth  cloth           = new Cloth
                {
                    Title       = model.Title,
                    Price       = model.Price,
                    Description = model.Description,
                    PhotoPath   = uniquieFileName
                };

                _clothRepository.Add(cloth);
                Alert("The product was created successfully!", NotificationType.success);
                return(RedirectToAction("details", new { id = cloth.Id }));
            }
            return(View());
        }
예제 #5
0
        public ActionResult UploadPicture([Bind(Include = "UploadPictureForm")] ClothCreateViewModel model, HttpPostedFileBase[] uploadImages)
        {
            _clotherService.CreatePicturesForCloth(model.UploadPictureForm.ClothId, uploadImages);

            return(RedirectToAction("Edit", new { id = model.UploadPictureForm.ClothId }));
        }