public async Task <DbResponse <VendorSliderModel> > AddAsync(VendorSliderModel model, string vendorUserName, ICloudStorage cloudStorage, IFormFile file) { try { if (file == null) { return(new DbResponse <VendorSliderModel>(false, "No image file found")); } var vendorId = _db.Registration.VendorIdByUserName(vendorUserName); if (vendorId == 0) { return(new DbResponse <VendorSliderModel>(false, "Invalid User")); } var fileName = FileBuilder.FileNameImage("store", file.FileName); model.ImageFileName = await cloudStorage.UploadFileAsync(file, fileName); model.VendorId = vendorId; _db.VendorStoreSlider.Add(model); _db.SaveChanges(); var data = _mapper.Map <VendorSliderModel>(_db.VendorStoreSlider.VendorStoreSlider); return(new DbResponse <VendorSliderModel>(true, "Success", data)); } catch (Exception e) { return(new DbResponse <VendorSliderModel>(false, e.Message)); } }
//Add Image Slider public async Task <IActionResult> AddImageSlider(VendorSliderModel model, IFormFile fileImage) { var response = await _vendorSlider.AddAsync(model, User.Identity.Name, _cloudStorage, fileImage); return(Json(response)); }