Exemplo n.º 1
0
 private Merger(IPrimaryContext ctx)
 {
     _context    = ctx;
     _existing   = new T[0];
     _updates    = new T[0];
     _mapUpdates = (e, u) => {};
 }
Exemplo n.º 2
0
 /// <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.");
 }
Exemplo n.º 5
0
 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.");
 }
Exemplo n.º 6
0
 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.");
 }
Exemplo n.º 7
0
 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");
 }
Exemplo n.º 8
0
 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");
 }
Exemplo n.º 9
0
        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.");
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
 public static Merger <T> Merge <T>(this IPrimaryContext ctx) where T : class
 {
     return(Merger <T> .SetContext(ctx));
 }
Exemplo n.º 12
0
 public CRUDService(IPrimaryContext context)
     : base(context)
 {
     _validationService = new ValidationService(context);
 }
Exemplo n.º 13
0
 public AuthService(IPrimaryContext context)
     : base(context)
 {
     _authValidator = new AuthUserValidator(this);
 }
Exemplo n.º 14
0
        /// <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);
            }
        }
Exemplo n.º 15
0
 public UserRoleService(IPrimaryContext ctx)
     : base(ctx)
 {
     _userRoleValidator = new UserRoleValidator(this);
 }
Exemplo n.º 16
0
 public OptionService(IPrimaryContext context)
 {
     Context = context;
 }
Exemplo n.º 17
0
 public CustomerLocationService(IPrimaryContext context)
     : base(context)
 {
     _customerLocationValidator = new CustomerLocationValidator(context);
 }
Exemplo n.º 18
0
 public CustomerService(IPrimaryContext context)
     : base(context)
 {
     _customerValidator = new CustomerValidator();
 }
Exemplo n.º 19
0
 public static Merger <T> SetContext(IPrimaryContext ctx)
 {
     return(new Merger <T>(ctx));
 }
Exemplo n.º 20
0
 public UserService(IPrimaryContext context, IAuthService authService)
     : base(context)
 {
     _userValidator = new UserValidator(context);
     _authService   = authService;
 }
Exemplo n.º 21
0
 public SettingsService(IPrimaryContext ctx)
 {
     Context = ctx;
 }
Exemplo n.º 22
0
 public ContractService(IPrimaryContext context)
     : base(context)
 {
     _contractValidator = new ContractValidator(context);
 }
Exemplo n.º 23
0
 public GoodService(IPrimaryContext context)
     : base(context)
 {
     _goodValidator = new GoodsValidator(context);
 }
Exemplo n.º 24
0
 public LocationServiceValidator(IPrimaryContext context)
 {
     RuleFor(ls => ls.Price)
     .NotEmpty()
     .WithMessage("Price is required");
 }
Exemplo n.º 25
0
 public LocationService(IPrimaryContext context)
     : base(context)
 {
     _locationServiceValidator = new LocationServiceValidator(context);
 }
Exemplo n.º 26
0
 protected BaseService(IPrimaryContext context)
 {
     Context = context;
 }