internal static void Validate(Rating role, ValidationResults results) { if (true)//some business-logic derived condition { results.AddResult ( new ValidationResult("some reason from SelfValidation method", role, "ValidateMethod", "error", null) ); } }
public bool AddNoteToUser(User givingNoteUser, User receivingNoteUser, int note) { try { VerifyUsers(givingNoteUser, receivingNoteUser); logger.logInfo("User " + givingNoteUser.Email + " try to add note " + note + " to user with email " + receivingNoteUser); if (!VerifyUsersAuctions(givingNoteUser, receivingNoteUser)) throw new AuctionException("User "+givingNoteUser.Email+" can not add a note to user "+receivingNoteUser.Email+" because it does not participate to any auction"); ICollection<User> users = DataMapperFactoryMethod.GetCurrentFactory().UserFactory.GetAllUsersThatGiveARaitingToAUser(receivingNoteUser); foreach(User user in users) if(user.Equals(givingNoteUser)) throw new AuctionException("User " + givingNoteUser.Email + " can not add a note to user " + receivingNoteUser.Email + " because it already give a note to that user"); Rating persistRating = new Rating(); persistRating.Date = DateTime.Now; persistRating.GivingNoteUser = givingNoteUser; persistRating.ReceivingNoteUser = receivingNoteUser; persistRating.Grade = note; DataMapperFactoryMethod.GetCurrentFactory().UserFactory.AddRating(persistRating); logger.logInfo("User " + givingNoteUser.Email + " succesfully add note " + note + " to user with email " + receivingNoteUser); return true; } catch (EntityDoesNotExistException exc) { logger.logError(exc); throw exc; } catch(ValidationException validationException) { logger.logError(validationException); throw validationException; } catch(AuctionException auctioException) { logger.logError(auctioException); throw auctioException; } }
public void AddRating(Rating rating) { using(var context = new AuctionModelContainer()) { context.Users.Attach(rating.GivingNoteUser); context.Users.Attach(rating.ReceivingNoteUser); context.Ratings.Add(rating); try { context.SaveChanges(); } catch (DbEntityValidationException exc) { String message = ""; IEnumerable<DbEntityValidationResult> errors = exc.EntityValidationErrors; foreach (DbEntityValidationResult error in errors) foreach (var validationError in error.ValidationErrors) message = message + " " + validationError.PropertyName + ". " + validationError.ErrorMessage; throw new ValidationException(message); } } }
public void UpdateRating(Rating rating) { using (var context = new AuctionModelContainer()) { context.Ratings.Attach(rating); var entry = context.Entry(rating); entry.Property(r => r.Grade).IsModified = true; try { context.SaveChanges(); } catch (DbEntityValidationException exc) { String message = ""; IEnumerable<DbEntityValidationResult> errors = exc.EntityValidationErrors; foreach (DbEntityValidationResult error in errors) foreach (var validationError in error.ValidationErrors) message = message + " " + validationError.PropertyName + ". " + validationError.ErrorMessage; throw new ValidationException(message); } } }
public void RemoveRating(Rating rating) { using(var context = new AuctionModelContainer()) { context.Ratings.Attach(rating); context.Ratings.Remove(rating); context.SaveChanges(); } }