示例#1
0
        public IActionResult Create(SlideShowCreateViewModel model)
        {
            var uploadResult = _fileService.Upload(model.File, "SlideShow", 1024 * 500);

            var serviceResult = new ServiceResult();

            if (uploadResult.IsSuccess)
            {
                serviceResult = _adminService.CreateSlideShow(model.ToDto(uploadResult.Data, model.File.Length));

                if (serviceResult.IsSuccess)
                {
                    Swal(true, "یک اسلایدشو با موفقیت اضافه شد");
                    return(RedirectToAction(nameof(Create)));
                }
            }
            else
            {
                serviceResult.Errors    = uploadResult.Errors;
                serviceResult.IsSuccess = false;
            }

            AddErrors(serviceResult);

            return(View(model));
        }
 public static SlideShowCreateDto ToDto(this SlideShowCreateViewModel source, string fileName, long length)
 {
     return(new SlideShowCreateDto
     {
         Description = source.Description,
         Link = source.Link,
         Title = source.Title,
         Length = length,
         FileName = fileName
     });
 }
示例#3
0
        public async Task <IActionResult> Create(SlideShowCreateViewModel model)
        {
            ViewBag.ListNgonNgu = ListNgonNgu;

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

            var dbItem = new SlideShow();

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

            InitParam.Db.SlideShow.Add(dbItem);
            await InitParam.Db.SaveChangesAsync();

            return(RedirectToAction(nameof(Edit), new { id = dbItem.Id }));
        }