예제 #1
0
        public async Task <IActionResult> Edit(SlideShowEditViewModel model)
        {
            ViewBag.ListNgonNgu = ListNgonNgu;

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var dbItem = await InitParam.Db.SlideShow.FirstOrDefaultAsync(h => h.Id == model.Id);

            if (dbItem == null)
            {
                return(NotFound());
            }

            dbItem.FkNgonNgu = model.NgonNguId;
            dbItem.TieuDe    = model.TieuDe;
            dbItem.HinhAnh   = model.HinhAnh;
            dbItem.LinkEvent = model.LinkSuKien;

            await InitParam.Db.SaveChangesAsync();

            return(RedirectToAction(nameof(Edit), new { id = model.Id }));
        }
예제 #2
0
 public static SlideShowEditDto ToDto(this SlideShowEditViewModel source, string fileName, long length)
 {
     return(new SlideShowEditDto
     {
         Description = source.Description,
         FileName = fileName,
         Id = source.Id,
         Length = length,
         Link = source.Link,
         Title = source.Title
     });
 }
예제 #3
0
        public IActionResult Edit(SlideShowEditViewModel model)
        {
            var uploadResult  = new ServiceResult <string>();
            var serviceResult = new ServiceResult <string>();

            if (model.File != null)
            {
                uploadResult = _fileService.Upload(model.File, "SlideShow", 1024 * 500);
            }

            if (!uploadResult.IsSuccess && model.File != null)
            {
                Swal(false, uploadResult.Errors.FirstOrDefault());
                return(RedirectToAction(nameof(Edit), new { id = model.Id }));
            }

            serviceResult = _adminService.EditSlideShow(model.ToDto(uploadResult.Data, model.File?.Length ?? 0));

            if (serviceResult.IsSuccess)
            {
                // delete file
                if (!string.IsNullOrEmpty(serviceResult.Data))
                {
                    _fileService.Delete(serviceResult.Data, "SlideShow");
                }

                Swal(true, "اسلایدشو با موفقیت ویرایش شد");
                return(RedirectToAction(nameof(Edit), new { id = model.Id }));
            }

            AddErrors(serviceResult);

            var data = _adminService.GetSlideShow(model.Id);

            return(View(data.ToViewModel()));
        }