public async Task <IActionResult> Create(PetWithImage model) { try { model.PetAccount.UserId = User.FindFirstValue(ClaimTypes.NameIdentifier); await _uploadImageService.CreatePetAccountUploadImage(model); _repo.PetAccount.Create(model.PetAccount); _repo.Save(); } catch (Exception e) { Console.WriteLine(e); ViewBag.error = "Failed to create Account"; return(RedirectToAction("Index", "Home")); } await _userManager.AddClaimAsync(await _userManager.FindByNameAsync(User.Identity.Name), new Claim(ClaimTypes.Role, "Pet Owner")); await _signInManager.RefreshSignInAsync(await _userManager.FindByNameAsync(User.Identity.Name)); _context.SaveChanges(); return(RedirectToAction("Index", "PetAccounts")); }
// GET: PetAccounts/Edit/5 public async Task <IActionResult> Edit(int id) { var petAccount = _repo.PetAccount.GetPetAccount(id); PetWithImage account = new PetWithImage(petAccount); if (petAccount == null) { return(NotFound()); } return(View(petAccount)); }
public async Task CreatePetAccountNullUploadImage(PetWithImage model) { byte[] imgdata = await System.IO.File.ReadAllBytesAsync(@"wwwroot\images\Default\default_petprofile.png"); PhotoBin petprofile = new PhotoBin(); petprofile.Content = imgdata; _repo.PhotoBin.Create(petprofile); _repo.Save(); // Retrieve photoid just saved to put into service model. model.PetAccount.PhotoBinId = _repo.PhotoBin.LastPhotoAddedId(); }
public async Task <IActionResult> Edit(PetWithImage model) { if (ModelState.IsValid) { _uploadImageService.EditPetAccountUploadImage(model); _repo.PetAccount.Update(model.PetAccount); _repo.Save(); return(View("Details", model.PetAccount)); } return(View("Details", model.PetAccount)); }
public async Task EditPetAccountUploadImage(PetWithImage model) { if (model.UploadFile == null) { return; } using (var memoryStream = new MemoryStream()) { await model.UploadFile.CopyToAsync(memoryStream); model.PetAccount.PetProfileImage = new PhotoBin(); model.PetAccount.PetProfileImage.Content = memoryStream.ToArray(); model.PetAccount.PetProfileImage.PhotoId = (int)model.PetAccount.PhotoBinId; _repo.PhotoBin.Update(model.PetAccount.PetProfileImage); _repo.Save(); } }
/* * Start of PetAccount UploadImage */ public async Task CreatePetAccountUploadImage(PetWithImage model) { if (model.UploadFile == null) { await CreatePetAccountNullUploadImage(model); return; } using (var memoryStream = new MemoryStream()) { await model.UploadFile.CopyToAsync(memoryStream); model.PetAccount.PetProfileImage = new PhotoBin(); model.PetAccount.PetProfileImage.Content = memoryStream.ToArray(); _repo.PhotoBin.Create(model.PetAccount.PetProfileImage); _repo.Save(); } // Retrieve photoid just saved to put into service model. model.PetAccount.PhotoBinId = _repo.PhotoBin.LastPhotoAddedId(); }
// GET: PetAccounts/Create public IActionResult Create() { PetWithImage account = new PetWithImage(); return(View(account)); }
// GET: RegistrationController public IActionResult PetOwnerRegistration() { PetWithImage account = new PetWithImage(); return(View(account)); }