Esempio n. 1
0
        public async Task <IActionResult> Update(ShopProfileViewModel shopProfileViewModel)
        {
            ShopProfile shopProfile = shopProfileViewModel.ShopProfileDto;

            ShopProfile result = await _shopProfileService.UpdateAsync(shopProfile);

            return(View("Index", new ShopProfileViewModel {
                ShopProfileDto = result
            }));
        }
Esempio n. 2
0
        public IActionResult ShopDetail(ShopProfileViewModel vm)
        {
            if (ModelState.IsValid)
            {
                string fileName    = "";
                string folderName  = "wwwroot\\Media\\";
                string webRootPath = _hostEnvironment.ContentRootPath;
                string newPath     = Path.Combine(webRootPath, folderName);
                if (!Directory.Exists(newPath))
                {
                    Directory.CreateDirectory(newPath);
                }
                if (vm.File != null)
                {
                    fileName = ContentDispositionHeaderValue.Parse(vm.File.ContentDisposition).FileName.Trim('"');
                    string fullPath = Path.Combine(newPath, fileName);
                    using (var stream = new FileStream(fullPath, FileMode.Create))
                    {
                        vm.File.CopyTo(stream);
                        vm.ImgUrl = @"/Media/" + fileName;
                    }
                }

                var claimsIdentity = (ClaimsIdentity)User.Identity;
                var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
                var shop           = _db.Shops.Find(claim.Value);

                shop.Name        = vm.Name;
                shop.Description = vm.Description;
                if (fileName != "")
                {
                    shop.ImgUrl = vm.ImgUrl;
                }
                else
                {
                    vm.ImgUrl = shop.ImgUrl;
                }
                try
                {
                    _db.Shops.Update(shop);
                    _db.SaveChanges();
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", e.InnerException.Message);
                }
            }
            return(View(vm));
        }
Esempio n. 3
0
        public IActionResult ShopDetail()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);


            var shop = _db.Shops.Find(claim.Value);

            if (shop != null)
            {
                var vm = new ShopProfileViewModel();
                vm.ApplicationUserId = shop.ApplicationUserId;
                vm.Description       = shop.Description;
                vm.Name   = shop.Name;
                vm.ImgUrl = shop.ImgUrl;

                return(View(vm));
            }
            return(NotFound());
        }