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