Exemplo n.º 1
0
        public ActionResult CreateGift(CreateGiftViewModel createGiftViewModel)
        {
            if (ModelState.IsValid)
            {
                var file = Request.Files["file"];

                var logoPath = "";

                if (file != null && file.ContentLength > 0)
                {
                    logoPath = Guid.NewGuid() + Path.GetExtension(file.FileName);
                    var path = Path.Combine(Server.MapPath(StringResources.GiftsLogoPath), logoPath);
                    file.SaveAs(path);
                }
                else
                {
                    logoPath = StringResources.NoGiftLogoPath;
                }

                createGiftViewModel.Logo = StringResources.GiftsLogoPath + logoPath;

                var newGift = Mapper.Map <DomainGift>(createGiftViewModel);
                _giftService.Create(newGift);
                return(RedirectToAction("CreateGiftSuccess"));
            }

            ModelState.AddModelError("", "Invalid model");
            return(View());
        }
Exemplo n.º 2
0
        private static string UploadImageGift(CreateGiftViewModel model)
        {
            var uploadFolder   = Path.Combine(_appEnvironment.ContentRootPath + "\\wwwroot\\img\\wheel");
            var uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName;
            var path           = Path.Combine(uploadFolder, uniqueFileName);
            var fileStream     = new FileStream(path, FileMode.Create);

            model.Image.CopyTo(fileStream);
            fileStream.Close();
            return(uniqueFileName);
        }
Exemplo n.º 3
0
        public IActionResult Create(CreateGiftViewModel vm)
        {
            var user = GetCurrentUserAsync().Result;

            Gift gift = new Gift()
            {
                Name      = vm.Name,
                Price     = vm.Price,
                PhotoPath = vm.PhotoPath,
                UserId    = user.Id
            };

            _giftRepo.Create(gift);

            return(RedirectToAction("Index", "Admin"));
        }