Пример #1
0
        /// <summary>
        /// 删除实体对象
        /// </summary>
        /// <param name="ID">主键id</param>
        /// <param name="DU">内存事务对象 默认为空</param>
        public virtual void Delete(object ID, UnitWork DU = null)
        {
            IRepository <T> objRepository = null;

            if (DU != null)
            {
                objRepository = DU.Get <T>();
            }
            else
            {
                objRepository = DalContext.Repository <T>();
            }
            var obj = objRepository.Get(ID);

            if (obj != null)
            {
                objRepository.Delete(obj);
            }
        }
Пример #2
0
        private static Invoice SaveInvoice(CartDto cart, DalContext context)
        {
            var invoice = new Invoice();

            invoice.Customer = cart.CustomerName;
            invoice.Date     = DateTime.Now;

            invoice.Rows = cart.Rows.Select(cr => GetInvoiceRow(cr, invoice)).ToList();

            var lastId = GetLastInvoiceId(context);

            invoice.Number = string.Format("#{0:D6}", lastId + 1);

            context.Invoices.Add(invoice);
            context.SaveChanges();

            invoice = context.Invoices.Single(inv => inv.Id == invoice.Id);
            return(invoice);
        }
Пример #3
0
        private static void LoadEventData(DalContext dalContext, string filePath)
        {
            try
            {
                Console.WriteLine($"Loading {filePath}");

                var reader      = new ArrangementReader.ArrangementReader();
                var arrangement = reader.Read(filePath);

                var theatreSeedData = new EventSeedData();
                theatreSeedData.Populate(dalContext, arrangement);
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(e);
                Console.ResetColor();
            }
        }
Пример #4
0
 /// <summary>
 /// 开始服务
 /// </summary>
 /// <param name="tel"></param>
 /// <param name="dics"></param>
 /// <returns></returns>
 public bool StartServic(string no)
 {
     try
     {
         var order     = DalContext.Repository <Order>().TableNoTracking.Where(o => o.BillNo == no).FirstOrDefault();
         var orderAddr = DalContext.Repository <OrderAddr>().TableNoTracking.Where(o => o.BillNo == no).FirstOrDefault();
         if (IsTel(orderAddr.Tel))
         {
             Dictionary <string, string> dics = new Dictionary <string, string>();
             dics.Add("ServerItemCode", no);
             dics.Add("RealStarTime", order.RealStartTime.ToString());
             return(MessageInterface.SmsSend(orderAddr.Tel, "开始服务", dics));
         }
     }
     catch (Exception exc)
     {
         NLogger.Error($"订单{no}'开始服务'短信发送失败, {exc.Message}");
     }
     return(false);
 }
Пример #5
0
        static void Main(string[] args)
        {
            if (args.Any() == false && Debugger.IsAttached)
            {
                args = new[]
                {
                    "1",
                    "User ID=postgres;Password=devpwd;Host=localhost;Port=5433;Database=tickettrader-event-definitions;Pooling=true",
                    @"D:\Mannelig\Dev\Magisterka\src\TicketTrader\TicketTrader.Web\wwwroot\scenes\theatre-clean.indexed.svg"
                };
            }


            Console.WriteLine("Populating db");

            int multiplication = Convert.ToInt32(args[0]);

            string connectionString = args[1];

            var builder = new DbContextOptionsBuilder <DalContext>();

            builder.UseNpgsql(connectionString);
            var dalContext = new DalContext(builder.Options);

            dalContext.Database.EnsureDeleted();
            dalContext.Database.Migrate();

            var filePaths = args.Skip(2).ToList();

            for (int i = 0; i < multiplication; i++)
            {
                Console.WriteLine($"Iteration {i}");

                foreach (var filePath in filePaths)
                {
                    LoadEventData(dalContext, filePath);
                }
            }

            Console.WriteLine("Finished");
        }
Пример #6
0
        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="obj">要修改实体对象</param>
        /// <param name="repository"> 非内存事务修改   定义BaseRepository<T> 先get对象 在修改对象 最后把定义的BaseRepository<T>传进来</param>
        /// <param name="DU">事务对象-  内存事务修改  非事务修改 为空</param>
        public virtual void Update(T obj, IRepository <T> repository = null, UnitWork DU = null)
        {
            IRepository <T> objRepository = null;

            if (repository == null && DU == null)
            {
                objRepository = DalContext.Repository <T>();
            }
            else
            {
                if (repository != null)
                {
                    objRepository = repository;
                }
                if (DU != null)
                {
                    objRepository = DU.Get <T>();
                }
            }
            objRepository.Update(obj);
        }
Пример #7
0
        /// <summary>
        /// remove a specific Person Entity
        /// </summary>
        /// <param name="id, caller, dbCtx"></param>
        /// <returns>person entity</returns>
        public string Delete(int?id, string caller, DalContext dbCtx)
        {
            Person person = null;

            try
            {
                // find person to delete
                person = Find(id, caller, dbCtx);

                // make sure not to delete the Picture entity, just the person
                person.PictureID = null;
                dbCtx.Persons.Remove(person);
                dbCtx.SaveChanges();
            }
            catch (Exception ex)
            {
                var errMsg = GetDbExceptionMsg(ex, caller);
                throw new Exception(errMsg);
            }
            return("Person Successfully Deleted");
        }
Пример #8
0
        public virtual PageResult <TResult> PageData <TResult, TOrderKey>(int pageIndex, int pageSize, Expression <Func <TResult, bool> > whereQuery, QueryableOrderEntry <TResult, TOrderKey> orderQuery, Expression <Func <T, TResult> > selector)
        {
            List <TResult> data = new List <TResult>();

            var query = DalContext.Repository <T>().TableNoTracking.Select(selector).Where(whereQuery);
            int count = query.Count();

            if (orderQuery.OrderDirection == OrderDirection.DESC)
            {
                query = query.OrderByDescending(orderQuery.Expression);
            }
            else
            {
                query = query.OrderBy(orderQuery.Expression);
            }

            data = query.Skip(pageSize * pageIndex).Take(pageSize).ToList();

            return(new PageResult <TResult> {
                ItemCount = count, Data = data
            });
        }
        public void Person_DeleteThenVerifyWasRemoved()
        {
            //Arrange
            string caller = "TestMethod Person_DeleteVerifyWasRemoved";

            Debug.WriteLine(caller);
            DalContext dbCtx     = dbContext;
            Person     result1   = null;
            Person     result2   = null;
            string     msg       = string.Empty;
            string     resultMsg = string.Empty;
            int?       id        = null;

            //Act
            try
            {
                // find a person to delete
                result1 = dbCtx.Persons.ToList().OrderBy(p => p.ID).LastOrDefault();
                id      = result1.ID;

                // delete person
                resultMsg = agentFactory.personAgent.Delete(id, caller, dbCtx);

                // verify that the person no longer exists
                result2 = agentFactory.personAgent.Find(id, caller, dbCtx);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                Debug.WriteLine(msg);
            }

            //Assert
            Assert.IsNotNull(result1);
            Assert.IsNull(result2);
            Assert.IsTrue(resultMsg.ToUpper() == "PERSON SUCCESSFULLY DELETED");
            Assert.IsTrue(msg.ToUpper().Contains("UNABLE TO FIND THE PERSON WITH ID="));
        }
        public void Person_GetForUpdate()
        {
            //Arrange
            string caller = "TestMethod Person_GetForUpdate";

            Debug.WriteLine(caller);
            DalContext      dbCtx     = dbContext;
            Person          result    = null;
            PersonViewModel viewModel = null;
            string          msg       = string.Empty;
            int?            id        = null;

            //Act
            try
            {
                // find a person to process
                result = dbCtx.Persons.ToList().OrderBy(p => p.ID).LastOrDefault();
                id     = result.ID;

                viewModel = agentFactory.personAgent.GetForUpdate(id, caller, dbCtx);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                Debug.WriteLine(msg);
            }

            //Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(viewModel);
            Assert.IsTrue(viewModel.ID == result.ID);
            Assert.IsTrue(viewModel.Name == result.Name);
            Assert.IsTrue(viewModel.Address == result.Address);
            Assert.IsTrue(viewModel.Age == result.Age);
            Assert.IsTrue(viewModel.Age > 0);
            Assert.IsTrue(viewModel.PictureList.Count() > 0);
        }
        public void Person_Find()
        {
            //Arrange
            string caller = "TestMethod Person_Find";

            Debug.WriteLine(caller);
            DalContext dbCtx   = dbContext;
            Person     result1 = null;
            Person     result2 = null;
            string     msg     = string.Empty;
            int?       id      = null;

            //Act
            try
            {
                // find a person to verify
                result1 = dbCtx.Persons.ToList().OrderBy(p => p.ID).LastOrDefault();
                id      = result1.ID;

                result2 = agentFactory.personAgent.Find(id, caller, dbCtx);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                Debug.WriteLine(msg);
            }

            //Assert
            Assert.IsNotNull(result1);
            Assert.IsNotNull(result2);
            Assert.IsTrue(result2.ID == result1.ID);
            Assert.IsTrue(result2.Name == result1.Name);
            Assert.IsTrue(result2.Address == result1.Address);
            Assert.IsTrue(result2.Age == result1.Age);
            Assert.IsTrue(result2.Age > 0);
        }
Пример #12
0
        public async Task <List <AttendenceData> > GetAttendanceData(IHttpContextAccessor context)
        {
            //var userId = Convert.ToInt32(context.HttpContext.Request.Headers[ServiceConstants.UserId][0]);
            try
            {
                InitializeRedisDb();

                List <AttendenceData> attendance = new List <AttendenceData>();
                using (IDalContext dalContext = new DalContext(_connectionStrings.HackConnection))
                {
                    var data = (await dalContext.DbConnection.QueryAsync <dynamic>("SELECT UserId, FirstName, LastName from UserDetails", null, commandType: CommandType.Text)).Select(x => new AttendenceData
                    {
                        UserId    = x.UserId,
                        FirstName = x.FirstName,
                        LastName  = x.LastName
                    });

                    if (data.Any())
                    {
                        attendance.AddRange(data);
                        foreach (var attendanceData in attendance)
                        {
                            attendanceData.Presence = await _redisDb.StringGetBitAsync(Attendancekey, attendanceData.UserId);
                        }
                    }
                }

                return(attendance);
            }
            catch (Exception ex)
            {
                return(null);

                Console.WriteLine(ex);
            }
        }
Пример #13
0
        /// <summary>
        /// Return all Person Entities requested
        /// </summary>
        /// <param name="queryArg, caller, dbCtx"></param>
        /// <returns>list of person entities</returns>
        public List <Person> GetList(string queryArg, string caller, DalContext dbCtx)
        {
            List <Person> persons = null;

            try
            {
                // check if this is a request for all persons
                if (queryArg.Equals("*"))
                {
                    persons = dbCtx.Persons.Include(p => p.Picture).AsNoTracking().OrderBy(p => p.Name).ToList();
                }
                else
                {
                    persons = dbCtx.Persons.Include(p => p.Picture).AsNoTracking().OrderBy(p => p.Name).Where(p => p.Name.Contains(queryArg)).ToList();
                }
            }
            catch (Exception ex)
            {
                var errMsg = GetDbExceptionMsg(ex, caller);
                throw new Exception(errMsg);
            }

            return(persons);
        }
Пример #14
0
        public async Task <ServiceResponse <List <BeaconResponse> > > GetBeacons(IHttpContextAccessor context, BeaconRequest request)
        {
            var response = new ServiceResponse <List <BeaconResponse> >()
            {
                IsSuccess = true, TokenStatus = TokenStatus.NotRequired, Data = new List <BeaconResponse>()
            };

            var securityToken = context.HttpContext.Request.Headers[ServiceConstants.SecurityToken][0];
            var userId        = Convert.ToInt32(context.HttpContext.Request.Headers[ServiceConstants.UserId][0]);

            if (userId <= 0)
            {
                response.IsSuccess   = false;
                response.TokenStatus = TokenStatus.Invalid;
                return(response);
            }

            using (IDalContext dalContext = new DalContext(_connectionStrings.HackConnection))
            {
                response = await _repository.GetBeacons(dalContext.DbConnection, request, userId, securityToken);
            }

            return(response);
        }
Пример #15
0
        /// <summary>
        /// 附加村料价格计算
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="mIds"></param>
        /// <param name="nums"></param>
        /// <returns></returns>
        public static List <decimal> GetMaterialPrice(int productId, Dictionary <int, int> materials)
        {
            List <decimal> prices = new List <decimal>();

            if (materials == null)
            {
                return(new List <decimal>());
            }

            var        repMaterial    = DalContext.Repository <Material>();
            List <int> mids           = materials.Select(o => o.Key).ToList();
            var        materialPrices = repMaterial.TableNoTracking.Where(o => mids.Contains(o.Id)).Select(o => new { o.Id, o.Price }).ToList();

            foreach (var s in materials)
            {
                var m = materialPrices.FirstOrDefault(a => a.Id == s.Key);
                if (m == null)
                {
                    throw new Exception($"Id为{s.Key}没找到价格高");
                }
                prices.Add(m.Price * s.Value);
            }
            return(prices);
        }
 public SceneDetailsProvider(DalContext dalContext)
 {
     _dalContext = dalContext;
 }
Пример #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KnowledgeFactory"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public KnowledgeFactory(DalContext context)
     : base(context)
 {
 }
 public UsuariosController(DalContext context)
 {
     _context = context;
 }
Пример #19
0
 public PriceZoneListProvider(DalContext dalContext, ICurrentDateTimeProvider currentTimeProvider)
 {
     _dalContext  = dalContext;
     _currentTime = currentTimeProvider;
 }
 public JuradosController(DalContext context)
 {
     _context = context;
 }
Пример #21
0
 public void Delete(T item)
 {
     DalContext.Set <T>().Remove(item);
 }
Пример #22
0
 public void Update(T item)
 {
     DalContext.Set <T>().Attach(item);
 }
Пример #23
0
 public void Add(T item)
 {
     DalContext.Set <T>().Add(item);
 }
Пример #24
0
 public T GetBy(int id)
 {
     return(DalContext.Set <T>().SingleOrDefault(x => x.Id == id));
 }
Пример #25
0
 public IEnumerable <T> GetAll()
 {
     return(DalContext.Set <T>().ToList().AsEnumerable());
 }
Пример #26
0
 public OrderPaymentsService(DalContext dalContext)
 {
     _dalContext = dalContext;
 }
Пример #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileIncludeFactory"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public FileIncludeFactory(DalContext context)
     : base(context)
 {
 }
 public ClientOrdersProvider(DalContext context)
 {
     _context = context;
 }
Пример #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserFactory"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public UserFactory(DalContext context) : base(context)
 {
 }
Пример #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KeywordFactory"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public KeywordFactory(DalContext context)
     : base(context)
 {
 }