public async Task <IActionResult> Edit(int id, [Bind("animalID,animalName,species,age,gender")] Animal animal) { if (id != animal.animalID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(animal); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnimalExists(animal.animalID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(animal)); }
public async Task <IActionResult> Edit(int id, [Bind("ownerID,firstname,lastname,phonenumber")] Owner owner) { if (id != owner.ownerID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(owner); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OwnerExists(owner.ownerID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(owner)); }
public async Task <IActionResult> Edit(int id, [Bind("appointmentID,date,animalID,ownerID")] Appointment appointment) { if (id != appointment.appointmentID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(appointment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AppointmentExists(appointment.appointmentID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["animalID"] = new SelectList(_context.Animals, "animalID", "animalID", appointment.animalID); ViewData["ownerID"] = new SelectList(_context.Owners, "ownerID", "ownerID", appointment.ownerID); return(View(appointment)); }
public async Task <IActionResult> ConfirmEmail(int?id) { if (id == null) { return(NotFound()); } Users users = await _context.Users.FindAsync(id); if (users == null) { return(NotFound()); } users.ConfirmedEmail = true; _context.Update(users); await _context.SaveChangesAsync(); TempData["Message"] = "A sua conta foi ativada! Pode proseguir para o login!"; return(View("~/Views/Home/Index.cshtml")); }
public Shared.Animal UpdateAnimal(int shelterId, int animalId, string new_name, string dateOfBirth, bool isChecked, bool kidFriendly, string dateOfArrival, int new_shelterId) { var pickedAnimal = _context.Animals .FirstOrDefault(x => x.Id == animalId && x.ShelterId == shelterId); pickedAnimal.name = new_name; pickedAnimal.DateOfBirth = dateOfBirth; pickedAnimal.IsChecked = isChecked; pickedAnimal.KidFriendly = kidFriendly; pickedAnimal.DateOfArrival = dateOfArrival; pickedAnimal.ShelterId = new_shelterId; _context.Update(pickedAnimal); _context.SaveChanges(); return(pickedAnimal); }
public void UpdateAnimal(int shelterId, int animalId, shared.Animal animal) { var existingAnimal = _context.Animals .FirstOrDefault(x => x.ShelterId == shelterId && x.Id == animalId); existingAnimal.Name = animal.Name; existingAnimal.Race = animal.Race; existingAnimal.DateOfBirth = animal.DateOfBirth; existingAnimal.IsFertile = animal.IsFertile; existingAnimal.IsKidFriendly = animal.IsKidFriendly; existingAnimal.IsAnimalFriendly = animal.IsAnimalFriendly; existingAnimal.IsSpeciesFriendly = animal.IsSpeciesFriendly; existingAnimal.Since = animal.Since; existingAnimal.Bio = animal.Bio; existingAnimal.Allergies = animal.Allergies; existingAnimal.ShelterId = animal.ShelterId; _context.Update(existingAnimal); _context.SaveChanges(); }
public async Task <IActionResult> Edit(int id, [Bind("ProductID,Name,Quantity,WeekStock,MonthStock,AnimalTypeFK,ProductTypeFK")] Product product) { if (!GetAuthorization(4, 'u')) { return(NotFound()); } ViewBag.Permission = getPermissions(); if (!checkValues(product)) { setViewBags(); return(View(product)); } if (id != product.ProductID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(product); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.ProductID)) { return(NotFound()); } else { throw; } } TempData["Message"] = "Produto editado com sucesso!"; return(RedirectToAction(nameof(Index))); } setViewBags(); return(View(product)); }
public async Task <IActionResult> Edit(int id, [Bind("ProductTypeID,Name")] ProductType productType) { if (!GetAuthorization(3, 'u')) { return(NotFound()); } ViewBag.Permission = getPermissions(); if (!checkValues(productType)) { return(View(productType)); } if (id != productType.ProductTypeID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(productType); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductTypeExists(productType.ProductTypeID)) { return(NotFound()); } else { throw; } } TempData["Message"] = "Tipo de produto editado com sucesso!"; return(RedirectToAction(nameof(Index))); } return(View(productType)); }
public async Task <IActionResult> Edit(int id, [Bind("AnimalRaceID,Name")] AnimalRace animalRace) { if (!GetAuthorization(7, 'u')) { return(NotFound()); } ViewBag.Permission = getPermissions(); if (id != animalRace.AnimalRaceID) { return(NotFound()); } if (!checkValues(animalRace)) { return(View(animalRace)); } if (ModelState.IsValid) { try { _context.Update(animalRace); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnimalRaceExists(animalRace.AnimalRaceID)) { return(NotFound()); } else { throw; } } TempData["Message"] = "Raça de animal editada com sucesso!"; return(RedirectToAction(nameof(Index))); } return(View(animalRace)); }
public async Task <IActionResult> Edit(int id, [Bind("DonationID,DateOfDonation,UsersFK")] DonationIndexViewModel donationIVM) { /*if (id != donationIVM.EditDonation.DonationID) * { * return NotFound(); * }*/ if (!GetAuthorization(5, 'u')) { return(NotFound()); } ViewBag.Permission = getPermissions(); if (!checkValues(donationIVM)) { return(Redirect(nameof(Edit))); } if (ModelState.IsValid) { try { string selected = Request.Form["checkProduct"].ToString(); string[] selectedList = selected.Split(','); Donation toEdit = _context.Donation.FirstOrDefault(e => e.DonationID == id); toEdit.DateOfDonation = donationIVM.DateOfDonation; toEdit.UsersFK = donationIVM.UsersFK; _context.Update(toEdit); _context.SaveChanges(); var x = 0; var allToRemove = _context.DonationProduct.Where(p => p.DonationFK == id); foreach (DonationProduct don in allToRemove) { var result3 = _context.Products.SingleOrDefault(p => p.ProductID == don.ProductFK); if (result3 != null) { result3.Quantity -= don.Quantity; _context.DonationProduct.Remove(don); } } if (selectedList[0] != "") { foreach (var temp in selectedList) { int prodKey = Convert.ToInt32(temp); int newQuant = 0; if (Request.Form["quantityProduct " + Convert.ToInt32(temp)] != "") { newQuant = Convert.ToInt32(Request.Form["quantityProduct " + Convert.ToInt32(temp)].ToString()); } DonationProduct donationProduct = new DonationProduct { DonationFK = id, ProductFK = prodKey, Quantity = newQuant }; x++; var quantityToRemove = allToRemove.Where(p => p.ProductFK == prodKey && p.DonationFK == id).ToList(); var result = _context.Products.SingleOrDefault(p => p.ProductID == prodKey); if (result != null) { result.Quantity += newQuant; _context.SaveChanges(); } _context.SaveChanges(); _context.Add(donationProduct); } } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DonationExists(donationIVM.EditDonation.DonationID)) { return(NotFound()); } else { throw; } } TempData["Message"] = "Doacao editada com sucesso!"; return(RedirectToAction(nameof(Index))); } return(View(donationIVM)); }
public async Task <IActionResult> Edit(int id, [Bind("RoleID,RoleName")] Roles roles) { if (!GetAuthorization(2, 'u')) { return(NotFound()); } ViewBag.Permission = getPermissions(); if (id != roles.RoleID) { return(NotFound()); } if (!checkValues(roles)) { setViewBags(id); return(View(roles)); } if (ModelState.IsValid) { try { _context.Update(roles); var componenets = _context.Components.ToList(); var roleRules = _context.RoleAuthorization.Where(e => e.RoleFK == id); foreach (RoleAuthorization roleAutho in roleRules.ToList()) { _context.Remove(roleAutho); _context.SaveChanges(); } foreach (var comp in componenets) { string selectedOptions = Request.Form[comp.Name].ToString(); string[] selectedOptionsList = selectedOptions.Split(','); RoleAuthorization rAutho = new RoleAuthorization { ComponentFK = comp.ComponentID, RoleFK = roles.RoleID, Create = false, Read = false, Update = false, Delete = false }; if (selectedOptionsList[0] != "") { foreach (var val in selectedOptionsList) { int crudID = Int32.Parse(val); switch (crudID) { case 1: rAutho.Create = true; break; case 2: rAutho.Read = true; break; case 3: rAutho.Update = true; break; case 4: rAutho.Delete = true; break; default: break; } } } if (rAutho.Delete || rAutho.Create || rAutho.Update) { rAutho.Read = true; } _context.Add(rAutho); _context.SaveChanges(); } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RolesExists(roles.RoleID)) { System.Diagnostics.Debug.WriteLine("*************************"); System.Diagnostics.Debug.WriteLine("Caught Exception"); System.Diagnostics.Debug.WriteLine("*************************"); return(NotFound()); } else { throw; } } TempData["Message"] = "Permissão editada com sucesso!"; return(RedirectToAction(nameof(Index))); } setViewBags(id); return(View(roles)); }
public async Task <IActionResult> Edit(int id, [Bind("AnimalID,Name,DateOfBirth,Disinfection,Neutered,Description,Foto,Picture,AnimalTypeFK,AnimalRaceFK,OwnerFK")] Animal animal) { if (!GetAuthorization(8, 'u')) { return(NotFound()); } ViewBag.Permission = getPermissions(); if (id != animal.AnimalID) { return(NotFound()); } if (!checkValues(animal)) { setViewBags(id); return(View(animal)); } if (ModelState.IsValid) { try { string selectedProducts = Request.Form["checkProduct"].ToString(); string[] selectedProductsList = selectedProducts.Split(','); string selectedGodfathers = Request.Form["checkGodfather"].ToString(); string[] selectedGodfatherList = selectedGodfathers.Split(','); if (animal.Foto != null) { var result = _context.Images.Where(e => e.AnimalFK == animal.AnimalID); if (result.Any()) { Images old = result.First(); System.IO.File.Delete(hostingEnvironment.WebRootPath + "/images/Galeria_" + animal.AnimalID + "/" + old.FileName); _context.Images.Remove(old); _context.SaveChanges(); } else { System.IO.Directory.CreateDirectory(hostingEnvironment.WebRootPath + "/images/Galeria_" + animal.AnimalID); } var uploads = Path.Combine(hostingEnvironment.WebRootPath, "images/Galeria_" + animal.AnimalID); var uniqueFileName = GetUniqueFileName(animal.Foto.FileName); var filePath = Path.Combine(uploads, uniqueFileName); animal.Foto.CopyTo(new FileStream(filePath, FileMode.Create)); Images image = new Images() { AnimalFK = animal.AnimalID, Name = animal.Foto.Name, Length = animal.Foto.Length, FileName = uniqueFileName, ContentType = animal.Foto.ContentType, ContentDisposition = animal.Foto.ContentDisposition }; _context.Add(image); _context.SaveChanges(); } _context.Update(animal); _context.SaveChanges(); removeAnimalProducts(id); if (selectedProductsList[0] != "") { foreach (var temp in selectedProductsList) { int prodKey = Convert.ToInt32(temp); AnimalProduct aniProd = new AnimalProduct() { AnimalFK = id, ProductFK = prodKey }; _context.Add(aniProd); _context.SaveChanges(); } } removeGodFathers(id); if (selectedGodfatherList[0] != "") { foreach (var temp in selectedGodfatherList) { int godkey = Convert.ToInt32(temp); AnimalUsers aniUsers = new AnimalUsers() { AnimalFK = id, UsersFK = godkey }; _context.Add(aniUsers); _context.SaveChanges(); } } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnimalExists(animal.AnimalID)) { return(NotFound()); } else { throw; } } TempData["Message"] = "Animal editado com sucesso!"; return(RedirectToAction(nameof(Index))); } setViewBags(id); return(View(animal)); }