public async Task <SweetAlertExtenstion> UpdateAsync(NewsUpdateViewModel model)
        {
            try
            {
                var entity = await GetByIdAsync(model.Id);

                entity = (News)Mapper.Map(model, entity, typeof(NewsUpdateViewModel), typeof(News));

                #region ذخیره فایل مورد نظر

                if (model.ImageFile != null)
                {
                    //حذف فایل قبلی
                    await MFile.Delete(entity.ImageAddress);

                    // ذخیره فایل جدید
                    entity.ImageAddress = await MFile.Save(model.ImageFile, "Uploads/NewsImages");
                }

                #endregion

                await DbContext.SaveChangesAsync();

                return(SweetAlertExtenstion.Ok());
            }
            catch (Exception e)
            {
                return(SweetAlertExtenstion.Error());
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Update(NewsUpdateViewModel model)
        {
            var result = await _newsRepository.UpdateAsync(model);

            TempData.AddResult(result);

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Update(NewsUpdateViewModel model)
        {
            var result = await _newsRepository.UpdateAsync(model);

            TempData.AddResult(result);

            return(Redirect(IndexUrlWithQueryString));
        }