コード例 #1
0
        public IActionResult PopularProductEdit(int id)
        {
            var entity = _popularProductServices.GetById(id);
            var model  = new PopularProductModel()
            {
                PopularProductId = entity.PopularProductId,
                Title            = entity.Title,
                Url   = entity.Url,
                Image = entity.Image
            };

            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> PopularProductEdit(PopularProductModel popularProductModel, IFormFile formFile)
        {
            var entity = _popularProductServices.GetById(popularProductModel.PopularProductId);

            entity.PopularProductId = popularProductModel.PopularProductId;
            entity.Title            = popularProductModel.Title;
            entity.Url = popularProductModel.Url;

            if (formFile != null)
            {
                var extention  = Path.GetExtension(formFile.FileName);
                var randomName = string.Format($"{Guid.NewGuid()}{extention}");
                entity.Image = randomName;
                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\img", randomName);

                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await formFile.CopyToAsync(stream);
                }
            }
            _popularProductServices.Update(entity);
            return(RedirectToAction("PopularProductList"));
        }