示例#1
0
        public PersonRetreivalService(IPersonRepository personRepo, IWebApiContext api)
        {
            /*
             * So, we need to work with a DB connection and a web service client in this class.
             * Why not just create them here?
             * You could write:
             *      _database = new DatabaseContext();
             *
             * ...but, with that one line, you've intertwined your PersonRetreivalService logic with the
             * database logic. Now, if we want to write automated tests, you can't test PersonRetreivalService
             * without inherently testing the database methods as well. This migh sound good at first, but
             * the problem is, when your SyncPersons method fails the tests, was it because something went wrong
             * in this class or is it something in the database that is causing the problem?
             *
             * Also, if you create the web service client here, every time you run your tests, you depend on data
             *  coming from the actual web service. That data is not static; it is not 100% known data. You cannot
             *  predict the results when the data is not known. You cannot put in specific tests, like:
             *      Get Person where Id == 1, and his FirstName should be 'Billy'
             *
             * So, the better solution is to require a database context in the constructor. That way, when we want
             * to perform automated testing, we can just send in some simple database object that we build ourselves
             * entirely for the purpose of testing. That database we pass in can contain a known set of data so that
             * we can predict the results!
             */

            // set the local variables with the arguments from the constructor
            // Is this a real database, or one that's mocked up for testing?
            // I don't really care, as long as it works!!!
            _personRepo = personRepo ?? throw new ArgumentNullException(nameof(personRepo));
            // same with the api. As long as whatever got passed in implements
            //  the GetPersons method, I don't give a shit what it is!!!
            _api = api ?? throw new ArgumentNullException(nameof(api));
        }
        public static void AuditTrack(this AppStorageContext ctx, IWebApiContext workContext)
        {
            if (workContext == null)
            {
                return;
            }

            var now = DateTime.Now;

            var addedAuditedEntities = ctx.ChangeTracker.Entries <ReadModelBase>()
                                       .Where(p => p.State == EntityState.Added)
                                       .Select(p => p.Entity);

            var modifiedAuditedEntities = ctx.ChangeTracker.Entries <ReadModelBase>()
                                          .Where(p => p.State == EntityState.Modified)
                                          .Select(p => p.Entity);

            if (!modifiedAuditedEntities.Any() && !addedAuditedEntities.Any())
            {
                return;
            }

            var currentUser = workContext.UserName ?? "System";

            foreach (var added in addedAuditedEntities)
            {
                added.CreatedBy    = currentUser;
                added.CreatedDate  = now;
                added.Deleted      = false;
                added.ModifiedBy   = currentUser;
                added.ModifiedDate = now;
            }

            foreach (var modified in modifiedAuditedEntities)
            {
                modified.ModifiedBy   = currentUser;
                modified.ModifiedDate = now;

                if (modified is ISoftDelete)
                {
                    if (modified.Deleted.HasValue && modified.Deleted.Value)
                    {
                        modified.DeletedBy   = currentUser;
                        modified.DeletedDate = now;
                    }
                }
            }
        }
示例#3
0
 protected BaseService(IWebApiContext context)
 {
     Context = context;
 }
 public QuestionService(IWebApiContext context) : base(context)
 {
 }
示例#5
0
 public PhoneNumberService(IWebApiContext context) : base(context)
 {
 }
示例#6
0
 public TimeSlotService(IWebApiContext context) : base(context)
 {
 }
 public DiaporamaImageService(IWebApiContext context) : base(context)
 {
 }
示例#8
0
 public StateService(IWebApiContext context) : base(context)
 {
 }
 public UserService(IWebApiContext context) : base(context)
 {
 }
示例#10
0
 public AboutTextService(IWebApiContext context) : base(context)
 {
 }
 public PermissionService(IWebApiContext context) : base(context)
 {
 }
示例#12
0
 public FuncionarioRepository(IWebApiContext context)
 {
     // Inicializa dados de conexão com o BD e GridFS
     _context = context;
     _gridFS  = context.GridFS;
 }
示例#13
0
 public PhoneTypeService(IWebApiContext context) : base(context)
 {
 }
示例#14
0
 protected BaseCrudService(IWebApiContext context)
     : base(context)
 {
 }
 public PersonalInformationService(IWebApiContext context) : base(context)
 {
 }
 public RegistrationService(IWebApiContext context) : base(context)
 {
 }
 public ActionTokenService(IWebApiContext context) : base(context)
 {
 }
示例#18
0
 public GlobalExceptionFilter(IWebApiContext apiContext)
 {
     _workContext = apiContext;
 }
示例#19
0
 public WebApiRepository(IWebApiContext context)
 {
     _context = context;
 }
示例#20
0
 public JobService(IWebApiContext context) : base(context)
 {
 }
 public FollowUpService(IWebApiContext context) : base(context)
 {
 }
 public AppointmentService(IWebApiContext context) : base(context)
 {
 }
 public CustomerService(IWebApiContext context) : base(context)
 {
 }
 public AppStorageContext(IOptions <StorageContextOptions> options, IWebApiContext workContext, IMediator mediator) : base(options)
 {
     _workContext = workContext;
     _mediator    = mediator;
 }
 public ResponseService(IWebApiContext context) : base(context)
 {
 }
示例#26
0
 public WebApiController(IWebApiContext context)
 {
     this.Context = context;
 }