예제 #1
0
 public int Delete(T data)
 {
     try
     {
         _context.Set <T>().Update(data);
         return(_context.SaveChanges());
     }
     catch (Exception ex)
     {
         throw new Exception("Erro Inesperado. " + ex.Message);
     }
 }
        public HttpResponseMessage Print(string periode, string posisi, string jumlah)
        {
            try
            {
                ReportParameter[] Params = new ReportParameter[5];
                string            Nomor  = String.Format("{0}/JPS-HR/SK/VI{1}/{2}", DateTime.Now.ToString("FFF"), DateTime.Now.Month.ToString("00"), DateTime.Now.Year);
                Params[0] = new ReportParameter("NomorSurat", Nomor);
                Params[1] = new ReportParameter("WeekDay", TodayName());
                Params[2] = new ReportParameter("Today", MonthName());
                Params[3] = new ReportParameter("Periode", periode);
                Params[4] = new ReportParameter("Posisi", ctx.Set <Lowongan>().Find(posisi).Nama);

                ReportDataSource reportDs = new ReportDataSource("DataSet1", genRepo.FindRankingPosisi(periode, posisi, jumlah));

                using (LocalReport localReport = new LocalReport())
                {
                    string rdlc = "print";

                    localReport.DataSources.Add(reportDs);


                    localReport.ReportPath = GetReportPath(rdlc);
                    localReport.SetParameters(Params);
                    localReport.Refresh();

                    return(ShowPdfReport(localReport, "hasil_akhir", "0.2", "8.27", "11.69", "0.30", "0.40", "0.20"));
                }
            }
            catch (ReportViewerException ex)
            {
                throw new Exception(ex.InnerException.Message);
            }
        }
예제 #3
0
        /// <summary>
        /// Generic construtor based on a specific DbContext.
        /// </summary>
        /// <param name="dbContext"></param>
        public GenericRepository(GenericContext <TContext> dbContext)
        {
            _dbContext = dbContext ?? throw new ArgumentNullException("dbContext");
            _dbContext.SetTrackingBehavior();

            try
            {
                DbSet = dbContext.Set <TEntity>();
            }
            catch (InvalidOperationException ex)
            {
                throw new Exception(string.Format(Errors.Possible_0, $"map the entity: {this.GetType().Name}"), ex);
            }
        }
예제 #4
0
        public void Execute(params Command[] commands)
        {
            IContext context = new GenericContext();

            context.Set(new RequestTimeContext(DateTime.Now), true);
            foreach (Command command in commands)
            {
                this.Send <QueueCommand, Task <QueueCommandResult> >(new QueueCommand(command, context))
                .To <ICommandProcessor>()
                .Result
                .Completion
                .Wait();
            }
        }
예제 #5
0
        internal void Receive(
            AggregateCommandHandler <Customer> handler,
            RepositoryFake <Customer> repo,
            IContext context,
            Customer customer,
            ID customerID
            )
        {
            GIVEN["a handler instance and a service provider"] = () => {
                handler = new AggregateCommandHandler <Customer>();
                IServiceProvider sp = new ServiceProviderFake().Register <IRepository <Customer> >(
                    repo = Substitute.ForPartsOf <RepositoryFake <Customer> >());
                context  = new GenericContext();
                context.Set(sp, false);
            };

            When["sending a create message to the aggregate"] = () => Send(customerID = ID.NewID(), new Customer.Create());
            Then["the aggregate gets created"] = async() => customer = await repo.Get(customerID);

            AND["it receives the command"] = () => customer.Commands.Should().BeEmpty();

            When["sending a non-create message to the aggregate"] = () => {
                repo.ClearReceivedCalls();
                customer.Commands.Clear();
                return(Send(customerID, new Customer.Promote()));
            };
            Then["the aggregate is loaded and saved"] = async() => {
                await repo.Received().Get(customerID);

                await repo.Received().Save(customer);
            };
            AND["it receives the command"] = () => customer.Commands.Should().ContainSingle(m => m is Customer.Promote);

            When["sending a message that does not belong to the aggregate"] = () => {
                repo.ClearReceivedCalls();
                return(Send(customerID, new Order.Ship()));
            };
            THEN["no action is performed"] = () => repo.ReceivedCalls().Should().BeEmpty();


            Task Send(ID target, ICommandMessage message)
            {
                Maybe <Task> result = handler.Receive(new HandleCommand(
                                                          new Command(message, target), context));

                return(result is Some <Task> t ? (Task)t : Task.CompletedTask);
            }
        }
예제 #6
0
        // TODO: Put strings into the resources.
        //
        public virtual async Task <IReferenceKeyProvider <TKey> > RequireReferenceKeyProviderAsync <TKey>(PersistenceEntityReferenceKeyTypeDescriptor keyTypeDescriptor, IContext ctx = default)
            where TKey : struct
        {
            await Task.CompletedTask;
            var provider = InitDA(location: ref _referenceKeyProvider, factory: create, cleanup: cleanup);

            if (provider is IReferenceKeyProvider <TKey> requiredProvider)
            {
                return(requiredProvider);
            }
            else
            {
                throw new EonException(message: $"Type of existing provider is not compatible with the required type.{Environment.NewLine}Type of existing provider:{provider.GetType().FmtStr().GNLI2()}{Environment.NewLine}Required type of provider:{typeof(IReferenceKeyProvider<TKey>).FmtStr().GNLI2()}");
            }
            //
            IReferenceKeyProvider create()
            {
                var locSettings = ReferenceKeyProviderSettings;

                if (locSettings is null)
                {
                    throw new EonException(message: $"There is no the reference key provider settings.{Environment.NewLine}\tComponent:{this.FmtStr().GNLI2()}");
                }
                else if (locSettings.IsDisabled)
                {
                    throw new EonException(message: $"Usage of the reference key provider not enabled by the settings.{Environment.NewLine}\tComponent:{this.FmtStr().GNLI2()}");
                }
                else
                {
                    var locFactory = ServiceProvider.GetRequiredService <IReferenceKeyProviderFactory>();
                    if (locFactory.CanCreate(arg: locSettings))
                    {
                        using (var locCtx = new GenericContext(outerCtx: ctx)) {
                            locCtx.Set(prop: DependencyContextProps.DependenciesProp, value: this.ToValueHolder(ownsValue: false));
                            return(locFactory.CreateAsync(arg: ReferenceKeyProviderSettings, ctx: locCtx).Unwrap().WaitResultWithTimeout());
                        }
                    }
                    else
                    {
                        throw new EonException(message: $"The factory cannot create an instance of the reference key provider using the specified settings.{Environment.NewLine}\tFactory:{locFactory.FmtStr().GNLI2()}{Environment.NewLine}\tSettings:{locSettings.FmtStr().GNLI2()}{Environment.NewLine}\tComponent:{this.FmtStr().GNLI2()}");
                    }
                }
            }

            void cleanup(IReferenceKeyProvider locProvider)
            => locProvider?.Dispose();
        }
예제 #7
0
 public Department GetByDepartmentId(int id)
 {
     return(_genericContext.Set <Department>().Find(id));
 }
예제 #8
0
        public async Task <TEntity> GetAsync(string id)
        {
            var entity = await _context.Set <TEntity>().FirstOrDefaultAsync(e => e.Id == id);

            return(entity);
        }
예제 #9
0
 public void Add(T Model)
 {
     _genericContext.Set <T>().Add(Model);
 }
예제 #10
0
 protected EfEntityRepositoryBase(GenericContext context)
 {
     _context = context;
     _dbSet   = _context.Set <T>();
 }
예제 #11
0
 public Personel GetByPersonelId(int id)
 {
     return(_genericContext.Set <Personel>().Find(id));
 }
 public void Add <T>(T entity) where T : class
 {
     Context.Set <T>().Add(entity);
     Context.SaveChanges();
 }
예제 #13
0
 public virtual T GetById(int id)
 {
     return(context.Set <T>().Find(id));
 }
예제 #14
0
 public GenericRepository(GenericContext context)
 {
     _context  = context;
     _entities = _context.Set <T>();
     _query    = _entities;
 }
 private DbSet <T> TableForT()
 {
     return(db.Set <T>());
 }
예제 #16
0
 public void Insert(TEntity entity)
 {
     context.Set <TEntity>().Add(entity);
     context.SaveChanges();
 }
 public virtual void Add(T entity)
 {
     context.Set <T>().Add(entity);
     context.SaveChanges();
 }
 public virtual void Add(TEntity entity)
 {
     DbContext.Set <TEntity>().Add(entity);
     DbContext.SaveChanges();
 }