private Merger(IPrimaryContext ctx) { _context = ctx; _existing = new T[0]; _updates = new T[0]; _mapUpdates = (e, u) => {}; }
/// <summary> /// Sets all properties from a dictionary to the corresponding property /// name on the update object (assumes that types are the same between objects) /// </summary> /// <param name="dict">The dictionary containing the new values</param> /// <param name="updateObj">The object being updated</param> /// <param name="ctx">The db context</param> public static void Map <T>(IDictionary <string, object> dict, T updateObj, IPrimaryContext ctx) where T : class, IEntity { foreach (var propName in dict.Keys) { EntityHelper.SetPropValue(updateObj, propName, dict[propName]); ctx.Entry(updateObj).Property(propName).IsModified = true; } }
public CustomerLocationValidator(IPrimaryContext context) { RuleFor(cl => cl.Name) .NotEmpty() .WithName("Location Name") .WithMessage("Location Name is required") .Length(0, 50) .WithMessage("Location name must be less then 50 characters"); }
public ServiceDivisionValidator(IPrimaryContext context) { Context = context; RuleFor(s => s.Name) .NotEmpty() .Length(0, 50) .Must(BeAUniqueServiceDivision) .WithMessage("There are duplicate Service Divisions."); }
public ContractValidator(IPrimaryContext context) { RuleFor(s => s.StartDate) .Must(BeBeforeEndDate) .WithMessage("Start Date Must be before the End Date"); RuleFor(s => s.EndDate) .Must(BeNotInThePast) .WithMessage("End Date Can't be in the past."); }
public UserValidator(IPrimaryContext context) { Context = context; RuleFor(u => u.FirstName).NotEmpty().Length(0, 50); RuleFor(u => u.LastName).NotEmpty().Length(0, 50); RuleFor(u => u.Email).NotEmpty().Length(0, 50) .Matches(Utilities.RegexPatterns.EmailPattern) .WithMessage(Utilities.RegexPatterns.EmailErrorMsg) .Must(IsUniqueEmail) .WithMessage("This email address is already associated with an account."); }
public StateValidator(IPrimaryContext context) { Context = context; RuleFor(s => s.Name) .NotEmpty() .Length(0, 50) .Must(BeAUniqueState) .WithMessage("There are duplicate States."); RuleFor(t => t.TaxRate) .Must(BeInARange) .WithMessage("Please Enter Value Between 0 and 100"); }
public GoodsValidator(IPrimaryContext context) { RuleFor(c => c.Name) .NotEmpty() .WithName("Service Name") .WithMessage("Service Name is Required") .Length(0, 50) .WithMessage("Service name must be less than 50 characters"); RuleFor(p => p.Cost) .Must(CostLessThenPrice) .WithMessage("Cost can't be higher then price"); }
public CustomerSourceValidator(IPrimaryContext context) { Context = context; RuleFor(s => s.Name) .NotEmpty() .Length(0, 50); RuleFor(s => s.Name) .NotEmpty() .Length(0, 50) .Must(BeAUniqueSourceName) .WithMessage("There are duplicate Customer Source names."); }
public ValidationService(IPrimaryContext context) { Context = context; _contactvalidator = new ContactValidator(); _customervalidator = new CustomerValidator(); _userValidator = new UserValidator(context); _customerSourceValidator = new CustomerSourceValidator(context); _serviceAreaValidator = new ServiceAreaValidator(context); _serviceDivisionValidator = new ServiceDivisionValidator(context); _unitTypeValidator = new UnitTypeValidator(context); _stateValidator = new StateValidator(context); _goodsValidator = new GoodsValidator(context); _customerLocationValidator = new CustomerLocationValidator(context); _contractValidator = new ContractValidator(context); _locationServiceValidator = new LocationServiceValidator(context); }
public static Merger <T> Merge <T>(this IPrimaryContext ctx) where T : class { return(Merger <T> .SetContext(ctx)); }
public CRUDService(IPrimaryContext context) : base(context) { _validationService = new ValidationService(context); }
public AuthService(IPrimaryContext context) : base(context) { _authValidator = new AuthUserValidator(this); }
/// <summary> /// Deletes / adds values to a many-to-many relationship /// (assumes that the many-to-many relationship collection has an "Id" field) /// </summary> /// <typeparam name="TEntity">The type of entity that is being updated</typeparam> /// <param name="dbCollection">The collection of values currently in the database</param> /// <param name="newCollection">The new collection of values that should be in the database after update</param> /// <param name="ctx">The database context</param> /// <param name="idPropName">The field/column name for the primary key on the collection of entities</param> public static void SetDbCollectionValues <TEntity>(ICollection <TEntity> dbCollection, ICollection <TEntity> newCollection, IPrimaryContext ctx, string idPropName = "Id") where TEntity : Entity, new() { var existingIds = new HashSet <int>(dbCollection.Select(x => (int)x.GetType().GetProperty(idPropName).GetValue(x))); var newIds = new HashSet <int>(newCollection.Select(x => (int)x.GetType().GetProperty(idPropName).GetValue(x))); //deleted ones foreach (int delId in existingIds.Where(exId => !newIds.Contains(exId))) { dbCollection.Remove(dbCollection.Single(x => (int)x.GetType().GetProperty(idPropName).GetValue(x) == delId)); } //new ones foreach (int newId in newIds.Where(id => !existingIds.Contains(id))) { TEntity newObj = new TEntity(); newObj.GetType().GetProperty(idPropName).SetValue(newObj, newId); ctx.Entry(newObj).State = EntityState.Unchanged; dbCollection.Add(newObj); } }
public UserRoleService(IPrimaryContext ctx) : base(ctx) { _userRoleValidator = new UserRoleValidator(this); }
public OptionService(IPrimaryContext context) { Context = context; }
public CustomerLocationService(IPrimaryContext context) : base(context) { _customerLocationValidator = new CustomerLocationValidator(context); }
public CustomerService(IPrimaryContext context) : base(context) { _customerValidator = new CustomerValidator(); }
public static Merger <T> SetContext(IPrimaryContext ctx) { return(new Merger <T>(ctx)); }
public UserService(IPrimaryContext context, IAuthService authService) : base(context) { _userValidator = new UserValidator(context); _authService = authService; }
public SettingsService(IPrimaryContext ctx) { Context = ctx; }
public ContractService(IPrimaryContext context) : base(context) { _contractValidator = new ContractValidator(context); }
public GoodService(IPrimaryContext context) : base(context) { _goodValidator = new GoodsValidator(context); }
public LocationServiceValidator(IPrimaryContext context) { RuleFor(ls => ls.Price) .NotEmpty() .WithMessage("Price is required"); }
public LocationService(IPrimaryContext context) : base(context) { _locationServiceValidator = new LocationServiceValidator(context); }
protected BaseService(IPrimaryContext context) { Context = context; }