public new int SaveChanges()
        {
            foreach (ObjectStateEntry entry in ObjectStateManager.GetObjectStateEntries(EntityState.Added))
            {
                Type targetType = entry.Entity.GetType();

                PropertyInfo[] pInfoList;

                if (Dict.ContainsKey(targetType))
                {
                    pInfoList = Dict[targetType];
                }
                else
                {
                    pInfoList = targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                }
                foreach (PropertyInfo pInfo in pInfoList)
                {
                    if (pInfo.Name.Equals("InsertDate") || pInfo.Name.Equals("UpdateDate") || pInfo.Name.Equals("AccessDate") || pInfo.Name.Equals("RegistDate") || pInfo.Name.Equals("RegisterDateTime"))
                    {
                        pInfo.SetValue(entry.Entity, CurrentInfoHolder.GetBoundDateTime(), null);
                    }
                    else if (pInfo.Name.Equals("InsertUser") || pInfo.Name.Equals("UpdateUser") || pInfo.Name.Equals("RegisterSystem"))
                    {
                        pInfo.SetValue(entry.Entity, CurrentInfoHolder.GetBoundUser(), null);
                    }
                    else if (pInfo.Name.Equals("VersionNo") || pInfo.Name.Equals("Version"))
                    {
                        pInfo.SetValue(entry.Entity, 1, null);
                    }
                }
            }

            return(base.SaveChanges());
        }
        public new TEntity ApplyCurrentValues <TEntity>(string entitySetName, TEntity currentEntity) where TEntity : class
        {
            Type targetType = currentEntity.GetType();

            PropertyInfo[] pInfoList;

            if (Dict.ContainsKey(targetType))
            {
                pInfoList = Dict[targetType];
            }
            else
            {
                pInfoList = targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            }

            foreach (PropertyInfo pInfo in pInfoList)
            {
                if (pInfo.Name.Equals("UpdateTime"))
                {
                    if (!CurrentInfoHolder.GetBoundDateTime().HasValue)
                    {
                        var now = DateTime.Now;
                        pInfo.SetValue(currentEntity, now, null);
                    }
                    else
                    {
                        pInfo.SetValue(currentEntity, CurrentInfoHolder.GetBoundDateTime(), null);
                    }
                }
            }

            return(base.ApplyCurrentValues(entitySetName, currentEntity));
        }
        /// <summary>
        /// CurrentInfoHolderやObjectContextHolderの初期化をする
        /// </summary>
        /// <param name="actionContext"></param>
        public override void OnActionExecuting(ActionExecutingContext actionContext)
        {
            CurrentInfoHolder.Init();
            CurrentInfoHolder.BindDateTimeToThread(DateTime.UtcNow.UtcToJapanStandardTime());


            ObjectContextHolder.ObjectContext();
            base.OnActionExecuting(actionContext);
        }
Exemple #4
0
 public Services(string path)
 {
     FileManager         = new FileManager(path);
     BudgetService       = new BudgetService(FileManager);
     CartService         = new CartService(FileManager);
     GoalService         = new GoalService(FileManager);
     HistoryService      = new HistoryService(FileManager);
     PaymentService      = new PaymentService(FileManager);
     SchedulerService    = new SchedulerService(FileManager);
     ShoppingService     = new ShoppingService();
     StatisticsService   = new StatisticsService(FileManager);
     VerificationService = new VerificationService();
     CurrentInfoHolder   = new CurrentInfoHolder();
 }
        public new TEntity ApplyCurrentValues <TEntity>(string entitySetName, TEntity currentEntity) where TEntity : class
        {
            Type targetType = currentEntity.GetType();

            PropertyInfo[] pInfoList;

            if (Dict.ContainsKey(targetType))
            {
                pInfoList = Dict[targetType];
            }
            else
            {
                pInfoList = targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            }

            foreach (PropertyInfo pInfo in pInfoList)
            {
                if (pInfo.Name.Equals("UpdateDate") || pInfo.Name.Equals("UpdateDateTime") || pInfo.Name.Equals("AccessDate"))
                {
                    pInfo.SetValue(currentEntity, CurrentInfoHolder.GetBoundDateTime(), null);
                }
                else if (pInfo.Name.Equals("UpdateUser") || pInfo.Name.Equals("UpdateSystem"))
                {
                    pInfo.SetValue(currentEntity, CurrentInfoHolder.GetBoundUser(), null);
                }
                else if (pInfo.Name.Equals("VersionNo") || pInfo.Name.Equals("Version"))
                {
                    var versionNo = currentEntity.GetPropertyValue(pInfo.Name);
                    if (versionNo == null)
                    {
                        pInfo.SetValue(currentEntity, 1, null);
                    }
                    else if (versionNo is int)
                    {
                        pInfo.SetValue(currentEntity, Convert.ToInt32(versionNo) + 1, null);
                    }
                }
            }

            return(base.ApplyCurrentValues <TEntity>(entitySetName, currentEntity));
        }
 /// <summary>
 /// CurrentInfoHolderやObjectContextHolderの解除をする
 /// </summary>
 /// <param name="actionExecutedContext"></param>
 public override void OnActionExecuted(ActionExecutedContext actionExecutedContext)
 {
     CurrentInfoHolder.Clear();
     ObjectContextHolder.Dispose();
     base.OnActionExecuted(actionExecutedContext);
 }
        public new int SaveChanges()
        {
            foreach (ObjectStateEntry entry in ObjectStateManager.GetObjectStateEntries(EntityState.Added))
            {
                Type targetType = entry.Entity.GetType();

                PropertyInfo[] pInfoList;

                if (Dict.ContainsKey(targetType))
                {
                    pInfoList = Dict[targetType];
                }
                else
                {
                    pInfoList = targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                }
                foreach (PropertyInfo pInfo in pInfoList)
                {
                    if (pInfo.Name.Equals("InsertTime") || pInfo.Name.Equals("UpdateTime"))
                    {
                        if (!CurrentInfoHolder.GetBoundDateTime().HasValue)
                        {
                            var now = DateTime.Now;
                            pInfo.SetValue(entry.Entity, now, null);
                        }
                        else
                        {
                            pInfo.SetValue(entry.Entity, CurrentInfoHolder.GetBoundDateTime(), null);
                        }
                    }
                }
            }

            foreach (ObjectStateEntry entry in ObjectStateManager.GetObjectStateEntries(EntityState.Modified))
            {
                Type targetType = entry.Entity.GetType();

                PropertyInfo[] pInfoList;

                if (Dict.ContainsKey(targetType))
                {
                    pInfoList = Dict[targetType];
                }
                else
                {
                    pInfoList = targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                }

                foreach (PropertyInfo pInfo in pInfoList)
                {
                    if (pInfo.Name.Equals("UpdateTime"))
                    {
                        if (!CurrentInfoHolder.GetBoundDateTime().HasValue)
                        {
                            var now = DateTime.Now;
                            pInfo.SetValue(entry.Entity, now, null);
                        }
                        else
                        {
                            pInfo.SetValue(entry.Entity, CurrentInfoHolder.GetBoundDateTime(), null);
                        }
                    }
                }
            }

            return(base.SaveChanges());
        }