protected override ValidationResult IsValid(object value, ValidationContext validationContext) { ProblemDContext _context = (ProblemDContext)validationContext.GetService(typeof(ProblemDContext)); var matchingEmail = _context.petowner.SingleOrDefault(o => o.Email == (string)value); if (matchingEmail != null) { return(new ValidationResult("Email already exists in database")); } return(ValidationResult.Success); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { ProblemDContext _context = (ProblemDContext)validationContext.GetService(typeof(ProblemDContext)); var petOwner = _context.petowner.SingleOrDefault(o => o.Email == (string)value); if (petOwner == null) { return(new ValidationResult("There is no Pet Owner with that email address")); } return(ValidationResult.Success); }
public static bool CheckActiveUserVsPet(int?activeId, int petId, ProblemDContext _context) { var test = _context.petowner.ToList(); Pet transferPet = _context.pet.SingleOrDefault(p => p.Id == petId); if (activeId == null || transferPet == null || transferPet.PetOwnerId != (int)activeId) { return(false); } else { return(true); } }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { ProblemDContext _context = (ProblemDContext)validationContext.GetService(typeof(ProblemDContext)); PetOwnerLogin instance = (PetOwnerLogin)validationContext.ObjectInstance; var potentialOwner = _context.petowner.SingleOrDefault(o => o.Email == instance.LoginEmail); PasswordHasher <PetOwner> hasher = new PasswordHasher <PetOwner>(); if (potentialOwner != null && hasher.VerifyHashedPassword(potentialOwner, potentialOwner.Password, (string)value) != 0) { return(ValidationResult.Success); } return(new ValidationResult("Invalid login attempt")); }
public static bool CheckUserCanTransfer(int?activeId, int petId, int ownerId, ProblemDContext _context) { var transferPet = _context.pet.SingleOrDefault(p => p.Id == petId); if (activeId == null || transferPet == null || transferPet.PetOwnerId != (int)activeId || ownerId != (int)activeId) { return(false); } else { return(true); } }