public async Task <IActionResult> EditService(ServiceWithPhotoUpload model) { model.Service.Business = _repo.Business.GetBusiness(model.Service.BusinessId); var isAuthorized = await _authorizationService.AuthorizeAsync(User, model.Service.Business, new UserIdMatchRequirement()); if (!isAuthorized.Succeeded) { return(Forbid()); } try { await _uploadImageService.EditServiceUploadImage(model); _repo.Service.Update(model.Service); _repo.Save(); } catch { TempData["error"] = "Failed to update Service"; return(RedirectToAction("Home")); } TempData["success"] = "Service Updated"; return(RedirectToAction("Home")); }
public async Task <IActionResult> CreateService(ServiceWithPhotoUpload newService) { var business = _repo.Business.GetBusiness(newService.Service.BusinessId); BusinessInfoViewModel model = new BusinessInfoViewModel(business, _repo); var isAuthorized = await _authorizationService.AuthorizeAsync(User, business, new UserIdMatchRequirement()); if (!isAuthorized.Succeeded) { return(Forbid()); } try { await _uploadImageService.CreateServiceUploadImage(newService); _repo.Service.Create(newService.Service); _repo.Save(); TempData["success"] = "Service Successfully Added"; return(RedirectToAction("Home")); } catch { TempData["error"] = "Service failed to create. Try Again."; return(RedirectToAction("Home")); } }
public async Task CreateServiceNullUploadImage(ServiceWithPhotoUpload model) { byte[] imgdata = await System.IO.File.ReadAllBytesAsync(@"wwwroot\images\Default\default_servicethumbnail.png"); PhotoBin logo = new PhotoBin(); logo.Content = imgdata; _repo.PhotoBin.Create(logo); _repo.Save(); // Retrieve photoid just saved to put into service model. model.Service.PhotoBinId = _repo.PhotoBin.LastPhotoAddedId(); }
public async Task EditServiceUploadImage(ServiceWithPhotoUpload model) { if (model.UploadFile == null) { return; } using (var memoryStream = new MemoryStream()) { await model.UploadFile.CopyToAsync(memoryStream); model.Service.ServiceThumbnail = new PhotoBin(); model.Service.ServiceThumbnail.Content = memoryStream.ToArray(); model.Service.ServiceThumbnail.PhotoId = (int)model.Service.PhotoBinId; _repo.PhotoBin.Update(model.Service.ServiceThumbnail); _repo.Save(); } }
/* * Start of Service UploadImage */ public async Task CreateServiceUploadImage(ServiceWithPhotoUpload model) { if (model.UploadFile == null) { await CreateServiceNullUploadImage(model); return; } using (var memoryStream = new MemoryStream()) { await model.UploadFile.CopyToAsync(memoryStream); model.Service.ServiceThumbnail = new PhotoBin(); model.Service.ServiceThumbnail.Content = memoryStream.ToArray(); _repo.PhotoBin.Create(model.Service.ServiceThumbnail); _repo.Save(); } // Retrieve photoid just saved to put into service model. model.Service.PhotoBinId = _repo.PhotoBin.LastPhotoAddedId(); }
public async Task <IActionResult> EditService(int?id) { if (id == null) { return(View("Home")); } var service = _repo.Service.GetService((int)id); var business = _repo.Business.GetBusiness(service.BusinessId); var isAuthorized = await _authorizationService.AuthorizeAsync(User, business, new UserIdMatchRequirement()); if (!isAuthorized.Succeeded) { return(Forbid()); } service.Business = business; service.ServiceThumbnail = _repo.PhotoBin.GetPhoto(service.PhotoBinId); ServiceWithPhotoUpload serviceToEdit = new ServiceWithPhotoUpload(service); return(View(serviceToEdit)); }
public async Task <IActionResult> AddService(int?businessId) { if (businessId == null) { return(View("Home", "Business")); } var business = _repo.Business.GetBusiness((int)businessId); var isAuthorized = await _authorizationService.AuthorizeAsync(User, business, new UserIdMatchRequirement()); if (!isAuthorized.Succeeded) { return(Forbid()); } Service service = new Service(); service.BusinessId = business.BusinessId; service.Business = business; ServiceWithPhotoUpload serviceToCreate = new ServiceWithPhotoUpload(service); return(View(serviceToCreate)); }
public async Task <IViewComponentResult> InvokeAsync(ServiceWithPhotoUpload service) { _service = service; return(View(service)); }