public async Task <DbResponse <SliderListModel> > AddAsync(SliderAddModel model, string userName, ICloudStorage cloudStorage, IFormFile file) { try { var registrationId = _db.Registration.GetRegID_ByUserName(userName); if (registrationId == 0) { return(new DbResponse <SliderListModel>(false, "Invalid User")); } model.CreatedByRegistrationId = registrationId; if (file == null) { return(new DbResponse <SliderListModel>(false, "Invalid Data")); } var fileName = FileBuilder.FileNameImage("slider", file.FileName); model.ImageFileName = await cloudStorage.UploadFileAsync(file, fileName); _db.Slider.Add(model); _db.SaveChanges(); var data = _mapper.Map <SliderListModel>(_db.Slider.Slider); return(new DbResponse <SliderListModel>(true, "Success", data)); } catch (Exception e) { return(new DbResponse <SliderListModel>(false, e.Message)); } }
public async Task <IActionResult> PostHomeSlider(SliderAddModel model, IFormFile fileImage) { var response = await _slider.AddAsync(model, User.Identity.Name, _cloudStorage, fileImage); return(Json(response)); }