Ejemplo n.º 1
0
 public virtual void ChangeAndPersistPassword(Context context, PasswordConfig secConfig, String currentPasswordText, String newPasswordText, String confirmedPasswordText)
 {
     if (newPasswordText != confirmedPasswordText)
     {
         throw new iSabayaException(Messages.Security.NewPasswordsNotConfirmed.Format(context.Configuration.DefaultLanguage.Code));
     }
     if (this.PasswordMatch(currentPasswordText))
     {
         Password newPassword = new Password(this, secConfig, newPasswordText);
         if (null != Configuration.CurrentConfiguration &&
             PassPasswordHistoryCheck(secConfig.PasswordHistoryDepth, newPassword))
         {
             Password previouswPassword = this.CurrentPassword;
             this.CurrentPassword = newPassword;
             context.Persist(previouswPassword);
             context.Persist(newPassword);
         }
         else
         {
             throw new iSabayaException(Messages.Security.FailPasswordHistory.Format(context.Configuration.DefaultLanguage.Code));
         }
     }
     else
     {
         throw new iSabayaException(Messages.Security.CurrentPasswordIsNotValid.Format(context.Configuration.DefaultLanguage.Code));
     }
 }
Ejemplo n.º 2
0
 public override void Persist(Context context)
 {
     if (0 == base.ID)
     {
         context.Persist(this);
     }
     base.Persist(context);
     context.Persist(this);
 }
Ejemplo n.º 3
0
        //public static String GetUserInfo(this SelfAuthenticatedUser user, Context context)
        //{
        //    StringBuilder name = new StringBuilder(user.Name.ToString());
        //    foreach (PersonOrgRelation employer in user.Person.FindCurrentEmployments(context))
        //    {
        //        name.Append(", ");
        //        name.Append(employer.Organization.ToString());
        //        if (null != employer.OrgUnit)
        //        {
        //            name.Append("-");
        //            name.Append(employer.OrgUnit.ToString());
        //        }
        //    }
        //    return name.ToString();
        //}

        public static void Persist(this MultilingualString ms, Context context)
        {
            context.Persist(ms);
            foreach (MLSValue v in ms.Values)
            {
                v.Owner = ms;
                context.Persist(v);
            }
        }
Ejemplo n.º 4
0
        //public virtual bool HasBeenInactiveTooLong()
        //{
        //    if (this.EffectivePeriod.IsNullOrEmpty() || this.LastLoginTimestamp == TimeInterval.MinDate)
        //        return false;
        //    else
        //        return (DateTime.Now - this.LastLoginTimestamp).Days > Configuration.CurrentConfiguration.Security.MaxDaysOfInactivity;

        //    //if (this.EffectivePeriod.IsNullOrEmpty())
        //    //    return false;

        //    //if (this.LastLoginTimestamp == TimeInterval.MinDate)
        //    //    //user has never been logged in
        //    //    return (DateTime.Now - this.EffectivePeriod.From).Days > Configuration.CurrentConfiguration.Security.MaxDaysOfInactivity;
        //    //else
        //    //    return (DateTime.Now - this.LastLoginTimestamp).Days > Configuration.CurrentConfiguration.Security.MaxDaysOfInactivity;
        //}

        //public virtual List<Role> GetRoles()
        //{
        //    List<Role> roles = new List<Role>();
        //    foreach (UserRole role in UserRoles)
        //    {
        //        if (role.EffectivePeriod.To.Equals(TimeInterval.MaxDate)
        //            || DateTime.Now <= role.EffectivePeriod.To)
        //        {
        //            roles.Add(role.Role);
        //        }
        //    }
        //    return roles;
        //}

        //public virtual RoleMenu GetEffectiveMenuPermission(iSystem applicationID, int menuID)
        //{
        //    RoleMenu effectiveRoleMenu = null;
        //    foreach (UserRole ur in this.GetEffectiveRoles(applicationID))
        //    {
        //        foreach (RoleMenu rm in ur.Role.Menus)
        //        {
        //            if (rm.Menu.Id == menuID)
        //                rm.MergeMenuPermissionsTo(ref effectiveRoleMenu);
        //        }
        //    }
        //    return effectiveRoleMenu;
        //}

        //public virtual int GetEffectivePrivilegeLevel(iSystem application)
        //{
        //    int effectivePrivilegeLevel = 0;
        //    foreach (UserRole ur in this.GetEffectiveRoles(application))
        //    {
        //        if (ur.EffectivePeriod.Includes(DateTime.Now)
        //            && ur.Role.SystemID == application.SystemID)
        //        {
        //            if (effectivePrivilegeLevel < ur.Role.PrivilegeLevel)
        //                effectivePrivilegeLevel = ur.Role.PrivilegeLevel;
        //        }
        //    }
        //    return effectivePrivilegeLevel;
        //}

        //public virtual List<UserRole> GetEffectiveRoles(iSystem application)
        //{
        //    List<UserRole> roles = new List<UserRole>();
        //    foreach (UserRole ur in UserRoles)
        //    {
        //        if (ur.EffectivePeriod.Includes(DateTime.Now)
        //            && ur.Role.SystemID == application.SystemID)
        //        {
        //            roles.Add(ur);
        //        }
        //    }
        //    return roles;
        //}

        //public static IList<User> GetByOrg(Context context, Organization org)
        //{
        //    if (null == org)
        //        throw new iSabayaException("The parameter org is null.");

        //    ICriteria crit = context.PersistenceSession.CreateCriteria<User>().Add(Expression.Eq("", org));
        //    return crit.List<User>();
        //}

        //public static IList<User> List(Context context)
        //{
        //    return context.PersistenceSession.CreateCriteria<User>().List<User>();
        //}

        //public static IList<User> ListEffective(Context context, int applicationID)
        //{
        //    IList<SystemUser> systemUsers = SystemUser.ListEffective(context, applicationID);
        //    IList<User> users = new List<User>();
        //    foreach (SystemUser su in systemUsers)
        //    {
        //        User user = su.User;
        //        if (!user.IsDisable && user.EffectivePeriod.IsEffective())
        //            users.Add(user);
        //    }
        //    return users;
        //}

        //public static User GetScheduleAutoUser(Context context)
        //{
        //    return context.PersistenceSession.CreateCriteria<User>()
        //                    .Add(Expression.Eq("IsAutomaticSchedule", true))
        //                    .UniqueResult<User>();
        //}

        //public static User Find(Context context, int id)
        //{
        //    return context.PersistenceSession.Get<User>(id);
        //}

        public override void Persist(Context context)
        {
            if (null != this.Person && this.Person.PersonID == 0)
            {
                this.Person.Persist(context);
            }

            if (0 == this.UserID)
            {
                if (null == this.CurrentPassword)
                {
                    base.Persist(context);
                }
                else
                {
                    //cyclic reference between this and current password
                    Password curPwd = this.currentPassword;
                    this.currentPassword = null;
                    base.Persist(context);
                    context.Persist(curPwd);
                    this.currentPassword = curPwd;
                }
            }

            if (this.Passwords != null)
            {
                foreach (Password pwd in this.Passwords)
                {
                    context.Persist(pwd);
                }
            }

            if (this.UserRoles != null)
            {
                foreach (var userRole in this.UserRoles)
                {
                    context.Persist(userRole);
                }
            }

            if (this.ResponsibleOrgUnits != null)
            {
                foreach (var userOrg in this.ResponsibleOrgUnits)
                {
                    userOrg.Persist(context);
                }
            }

            base.Persist(context);
        }
Ejemplo n.º 5
0
 public static void Update(this MultilingualString ms, Context context)
 {
     foreach (MLSValue v in ms.Values)
     {
         context.Persist(v);
     }
 }
Ejemplo n.º 6
0
 public override void Persist(Context context)
 {
     context.Persist(this);
     foreach (PartyAddress a in this.Addresses)
     {
         a.Party = this;
         a.Save(context);
     }
     foreach (PartyAttribute a in this.Attributes)
     {
         a.Party = this;
         a.Save(context);
     }
     foreach (PartyCategory a in this.Categories)
     {
         a.Party = this;
         a.Save(context);
     }
     foreach (PartyIdentity a in this.Identities)
     {
         a.Party = this;
         a.Save(context);
     }
     foreach (PartyMoneyRateSchedule a in this.MoneyRateSchedules)
     {
         a.Party = this;
         a.Save(context);
     }
     foreach (PartyBankAccount a in this.AssociatedBankAccounts)
     {
         a.Party = this;
         a.Save(context);
     }
 }
Ejemplo n.º 7
0
 public override void Save(Context context)
 {
     context.Persist(this);
     foreach (PropertyTemplateBase pt in this.children)
     {
         pt.Save(context);
     }
 }
Ejemplo n.º 8
0
 public virtual void Save(Context context)
 {
     if (Title != null)
     {
         Title.Persist(context);
     }
     context.Persist(this);
 }
Ejemplo n.º 9
0
 public virtual void Save(Context context)
 {
     foreach (PropertyValueContainerBase value in children)
     {
         value.Save(context);
     }
     context.Persist(this);
 }
Ejemplo n.º 10
0
 public override void Save(Context context)
 {
     foreach (PropertyValueContainerBase valueGroup in this.Children)
     {
         valueGroup.Parent = this;
         valueGroup.Save(context);
     }
     context.Persist(this);
 }
Ejemplo n.º 11
0
 public override void Save(Context context)
 {
     context.Persist(this);
     foreach (PropertyValue pvalue in Values)
     {
         pvalue.Property = this;
         pvalue.Save(context);
     }
 }
Ejemplo n.º 12
0
 public override void Persist(Context context)
 {
     if (this.EffectivePeriod == TimeInterval.EmptyInterval)
     {
         context.PersistenceSession.Delete(this);
     }
     else
     {
         context.Persist(this);
     }
 }
Ejemplo n.º 13
0
 public override void Save(Context context)
 {
     base.Save(context);
     if (id == 0)
     {
         context.Persist(this);
     }
     else
     {
         context.PersistenceSession.Update(this);
     }
 }
Ejemplo n.º 14
0
 public virtual void Save(Context context)
 {
     if (0 == this.Name.MLSID)
     {
         this.Name.Persist(context);
     }
     if (0 == this.ShortName.MLSID)
     {
         this.ShortName.Persist(context);
     }
     context.Persist(this);
 }
Ejemplo n.º 15
0
 public virtual void Save(Context context)
 {
     if (null != this.Name)
     {
         this.Name.Persist(context);
     }
     if (null != this.ShortName)
     {
         this.ShortName.Persist(context);
     }
     context.Persist(this);
 }
Ejemplo n.º 16
0
 public virtual void Save(Context context)
 {
     if (ShortAffix != null)
     {
         ShortAffix.Persist(context);
     }
     if (Affix != null)
     {
         Affix.Persist(context);
     }
     context.Persist(this);
 }
Ejemplo n.º 17
0
 public override void Persist(Context context)
 {
     if (this.ID == 0)
     {
         context.Persist(this);
     }
     if (this.Agent.ID == 0)
     {
         this.Agent.Persist(context);
     }
     base.Persist(context);
     context.PersistenceSession.Update(this);
 }
Ejemplo n.º 18
0
        public virtual LoginResult Login(Context context, String passwordText, out bool userMustChangePassword)
        {
            LoginResult result = Authenticate(context, passwordText, out userMustChangePassword);

            if (result == LoginResult.AuthenticationSuccess)
            {
                if (LastLoginTimestamp != TimeInterval.MinDate && this.HasBeenInactiveTooLong())
                {
                    if (IsReinstated)
                    {
                        IsReinstated = false;
                    }
                    //else
                    //    return LoginResult.IsSuspended;
                }
                else if (this.ConsecutiveFailedLoginCount >= context.Configuration.Security.MaxConsecutiveFailedLogonAttempts &&
                         this.LastFailedLoginTimestamp > this.LastLoginTimestamp)
                {
                    this.LastFailedLoginTimestamp = DateTime.Now;
                    ++this.ConsecutiveFailedLoginCount;
                }
                else
                {
                    this.ConsecutiveFailedLoginCount = 0;
                    this.LastLoginTimestamp          = DateTime.Now;
                }
            }
            else
            {
                this.LastFailedLoginTimestamp = DateTime.Now;
                ++this.ConsecutiveFailedLoginCount;
            }

            using (ITransaction tx = context.PersistenceSession.BeginTransaction())
            {
                try
                {
                    context.Persist(this);
                    tx.Commit();
                }
                catch
                {
                    tx.Rollback();
                }
            };
            return(result);
        }
Ejemplo n.º 19
0
 public virtual void Save(Context context)
 {
     if (null != MultilingualName)
     {
         MultilingualName.Persist(context);
     }
     if (null != AbbreviatedName)
     {
         AbbreviatedName.Persist(context);
     }
     foreach (GeographicRegion r in Subregions)
     {
         r.Country     = this.Country;
         r.SuperRegion = this;
         r.Save(context);
     }
     context.Persist(this);
 }
Ejemplo n.º 20
0
        public override void Persist(Context context)
        {
            bool requireSecondPassUpdate = false;

            if (this.ID == 0)
            {
                if (this.AccountName != null)
                {
                    this.AccountName.Persist(context);
                }
                context.Persist(this);
                requireSecondPassUpdate = true;
            }
            else
            {
                context.PersistenceSession.Update(this);
            }

            base.Persist(context);

            foreach (BankAccountOwner o in this.Owners)
            {
                o.BankAccount = this;
                o.Save(context);
            }

            foreach (BankAccountBalance b in this.Balances)
            {
                b.Account = this;
                b.Persist(context);
            }

            foreach (FixedDeposit f in this.FixedDeposits)
            {
                f.Account = this;
                f.Persist(context);
            }

            if (requireSecondPassUpdate)
            {
                //this.UpdatedTS = DateTime.Now;
                context.PersistenceSession.Update(this);
            }
        }
Ejemplo n.º 21
0
        //public virtual DateTime FindScheduledDateForTimestamp(TimeSchedule workCalendar, TimeSchedule nonworkCalendar, DateTime timestamp)
        //{
        //    if (timestamp < this.EffectivePeriod.From)
        //        throw new iSabayaException("The calendar was not effective on the given timestamp.");

        //    int daysToExpiration = this.EffectivePeriod.To.Subtract(timestamp).Days;

        //    for (int i = 0; i < ((daysToExpiration < 366) ? daysToExpiration : 366); ++i)
        //    {
        //        TimeInterval workHours;
        //        DateTime d = timestamp.AddDays(i);

        //        //if (d > calendar.EffectivePeriod.To)
        //        //    throw new iSabayaException("Can't find a trade date");

        //        workHours = this.GetScheduledHourIntervalOn(d, workCalendar, nonworkCalendar);
        //        if (workHours == null) continue; //non-scheduled day
        //        if (workHours.From.Date >= timestamp.Date || workHours.Includes(timestamp))
        //            return workHours.From;
        //        break;
        //    }
        //    throw new iSabayaException("Can't find a scheduled date");
        //}

        //public virtual bool GetScheduledOrRescheduledDayOn(DateTime givenDate, int daysToSearch, TimeSchedule nonworkSchedule,
        //                                                out ScheduleDetail sd, out TimeInterval hourInterval)
        //{
        //    bool found = false;
        //    sd = null;
        //    hourInterval = null;

        //    TimeInterval searchInterval;

        //    switch (this.RescheduleIfHoliday)
        //    {
        //        case RescheduleOption.ScheduledDayAfter:
        //            searchInterval = this.EffectivePeriod.Intersect(givenDate, givenDate.AddDays(daysToSearch));
        //            if (!searchInterval.IsEmpty())
        //                for (DateTime d = searchInterval.From; d >= searchInterval.To; d = d.AddDays(1))
        //                {
        //                    if (GetScheduledDayAndNotAHoliday(d, nonworkSchedule, out sd, out hourInterval))
        //                    {
        //                        found = true;
        //                        break;
        //                    }
        //                }
        //            break;

        //        case RescheduleOption.ScheduledDayBefore:
        //            searchInterval = this.EffectivePeriod.Intersect(givenDate.AddDays(-daysToSearch), givenDate);
        //            if (!searchInterval.IsEmpty())
        //                for (DateTime d = searchInterval.To; d >= searchInterval.From; d = d.AddDays(-1))
        //                {
        //                    if (GetScheduledDayAndNotAHoliday(d, nonworkSchedule, out sd, out hourInterval))
        //                    {
        //                        found = true;
        //                        break;
        //                    }
        //                }
        //            break;

        //        default:
        //            if (GetScheduledDayAndNotAHoliday(givenDate, nonworkSchedule, out sd, out hourInterval))
        //            {
        //                found = true;
        //                break;
        //            }
        //            break;

        //    }
        //    return found;
        //}

        //private bool GetScheduledDayAndNotAHoliday(DateTime givenDate, TimeSchedule nonworkSchedule, out ScheduleDetail sd, out TimeInterval hourInterval)
        //{
        //    if (this.GetFirstMatchedScheduleDetailOnDate(givenDate.Date, out sd, out hourInterval))
        //        return (null == nonworkSchedule || !nonworkSchedule.IsScheduledDay(givenDate));
        //    else
        //        return false;
        //}

        //public virtual DateTime FindScheduledDateForTimestamp(DateTime timestamp, DateTime cutoffTime, int daysToSearch, TimeSchedule nonworkSchedule)
        //{
        //    ScheduleDetail sd;
        //    TimeInterval hourInterval = null;
        //    DateTime scheduledTimestamp;
        //    TimeInterval searchInterval;

        //    switch (this.RescheduleIfHoliday)
        //    {
        //        case RescheduleOption.ScheduledDayAfter:
        //            if (timestamp.TimeOfDay > cutoffTime.TimeOfDay)
        //            {
        //                timestamp = timestamp.AddDays(1);
        //                timestamp = new DateTime(timestamp.Year, timestamp.Month, timestamp.Day, 0, 0, 0);
        //            }
        //            searchInterval = this.EffectivePeriod.Intersect(timestamp, timestamp.AddDays(daysToSearch));

        //            if (!searchInterval.IsEmpty())
        //                for (DateTime d = searchInterval.From; d >= searchInterval.To; d = d.AddDays(1))
        //                {
        //                    if (GetScheduledDayAndNotAHoliday(d, nonworkSchedule, out sd, out hourInterval))
        //                        break;
        //                }
        //            break;

        //        case RescheduleOption.ScheduledDayBefore:
        //            if (timestamp.TimeOfDay <= cutoffTime.TimeOfDay)
        //            {
        //                timestamp = timestamp.AddDays(-1);
        //                timestamp = new DateTime(timestamp.Year, timestamp.Month, timestamp.Day, 0, 0, 0);
        //            }
        //            searchInterval = this.EffectivePeriod.Intersect(timestamp.AddDays(-daysToSearch), timestamp);
        //            if (!searchInterval.IsEmpty())
        //                for (DateTime d = searchInterval.To; d >= searchInterval.From; d = d.AddDays(-1))
        //                {
        //                    if (GetScheduledDayAndNotAHoliday(d, nonworkSchedule, out sd, out hourInterval))
        //                        break;
        //                }
        //            break;

        //        default:
        //            GetScheduledDayAndNotAHoliday(timestamp, nonworkSchedule, out sd, out hourInterval);
        //            break;

        //    }

        //    if (null == hourInterval)
        //        scheduledTimestamp = DateTime.MinValue;
        //    else
        //    {
        //        if (timestamp.Date == hourInterval.From.Date)
        //            scheduledTimestamp = timestamp;
        //        else
        //            scheduledTimestamp = hourInterval.From;
        //    }
        //    return scheduledTimestamp;
        //}

        public virtual void Save(Context context)
        {
            if (Title != null)
            {
                Title.Persist(context);
            }
            if (Description != null)
            {
                Description.Persist(context);
            }

            context.Persist(this);

            foreach (ScheduleDetail sd in scheduleDetails)
            {
                sd.Schedule = this;
                sd.Save(context);
            }
        }
Ejemplo n.º 22
0
 public virtual void Save(Context context)
 {
     if (this.Name != null)
     {
         this.Name.Persist(context);
     }
     if (this.AbbreviatedName != null)
     {
         this.AbbreviatedName.Persist(context);
     }
     if (this.NationalityName != null)
     {
         this.NationalityName.Persist(context);
     }
     if (this.RegionLevel1Title != null)
     {
         this.RegionLevel1Title.Persist(context);
     }
     if (this.RegionLevel2Title != null)
     {
         this.RegionLevel2Title.Persist(context);
     }
     if (this.RegionLevel3Title != null)
     {
         this.RegionLevel3Title.Persist(context);
     }
     if (this.RegionLevel4Title != null)
     {
         this.RegionLevel4Title.Persist(context);
     }
     if (this.level1RegionRootNode != null)
     {
         this.level1RegionRootNode.Save(context);
     }
     foreach (GeographicRegion r in Level1Regions)
     {
         r.Country = this;
         r.Save(context);
     }
     context.Persist(this);
 }
Ejemplo n.º 23
0
        public virtual void Save(Context context)
        {
            if (null != this.ShortTitle)
            {
                this.ShortTitle.Persist(context);
            }
            if (null != this.Title)
            {
                this.Title.Persist(context);
            }
            if (null != this.Description)
            {
                this.Description.Persist(context);
            }
            context.Persist(this);

            //foreach (FunctionMenu m in this.FunctionMenus)
            //{
            //    m.Function = this;
            //    m.Save(context);
            //}
        }
Ejemplo n.º 24
0
 public override void Persist(Context context)
 {
     if (null != this.Prefix && Prefix.AffixID == 0)
     {
         Prefix.Save(context);
     }
     if (null != this.Suffix && Suffix.AffixID == 0)
     {
         Suffix.Save(context);
     }
     if (null != this.FirstName)
     {
         FirstName.Persist(context);
     }
     if (null != this.LastName)
     {
         LastName.Persist(context);
     }
     if (null != this.MiddleName)
     {
         MiddleName.Persist(context);
     }
     context.Persist(this);
 }
Ejemplo n.º 25
0
 public override void Save(Context context)
 {
     context.Persist(this);
 }
Ejemplo n.º 26
0
        //#region static

        //public static IList<BankTransaction> GetTransactions(Context context, InvestmentInstrument instrument,
        //                                                    BankTransactionType transactionType,
        //                                                    TransactionStateCategory stateCategory,
        //                                                    DateTime transactionDate)
        //{
        //    ICriteria crit = context.PersistenceSession.CreateCriteria<BankTransaction>();
        //    if (transactionType != null) crit.Add(Expression.Eq("Type", transactionType));
        //    return crit.Add(Expression.Eq("Instrument", instrument))
        //                .CreateAlias("CurrentState", "cs")
        //                .Add(Expression.Eq("cs.StateCategory", stateCategory))
        //                .Add(Expression.Eq("TradeDate", transactionDate))
        //                .List<BankTransaction>();
        //}

        //public static IList<BankTransaction> GetTransactions(Context context, InvestmentInstrument instrument,
        //                                                    BankTransactionType transactionType,
        //                                                    TransactionStateCategory stateCategory)
        //{
        //    ICriteria crit = context.PersistenceSession.CreateCriteria<BankTransaction>();
        //    if (transactionType != null) crit.Add(Expression.Eq("Type", transactionType));
        //    return crit.Add(Expression.Eq("Instrument", instrument))
        //                .CreateAlias("CurrentState", "cs")
        //                .Add(Expression.Eq("cs.StateCategory", stateCategory))
        //                .List<BankTransaction>();
        //}

        //public static BankTransaction FindByTransactionNo(Context context, String transactionNo)
        //{
        //    ICriteria crit = context.PersistenceSession.CreateCriteria<BankTransaction>();
        //    crit.Add(Expression.Eq("TransactionNo", transactionNo));
        //    BankTransaction fundTransaction = crit.UniqueResult<BankTransaction>();
        //    return fundTransaction;
        //}

        //public static BankTransaction Find(Context context, Int64 tranId)
        //{
        //    return (BankTransaction)context.PersistenceSession.Get(typeof(BankTransaction), tranId);
        //}

        //#endregion static

        #region abstract

        //public abstract String ToPassbookLine();
        //public abstract void CreateInvestmentIfNull();
        //public abstract void Commit(Context context);
        //public abstract void SaveChildTransaction(Context context);
        //public abstract void SaveCousinTransaction(Context context);

        #endregion abstract

        #region operations


        //public virtual bool Rollback(Context context, ContraTransaction contraTran)
        //{
        //    throw new NotImplementedException();
        //}

        //public virtual String ToPassbookLine()
        //{
        //    return null;
        //}

        //public abstract Money Amount { get; set; }

        //public virtual double Units
        //{
        //    get { return 0d; }
        //    set { }
        //}

        //public virtual bool IsBeingRollbacked
        //{
        //    get { return this.RollbackStatus == InvestmentTransactionRollbackStatus.PendingRollback; }
        //}



        //public virtual bool HasBeenRollbacked
        //{
        //    get { return this.RollbackStatus == InvestmentTransactionRollbackStatus.BeenRollbacked; }
        //}

        //public virtual String ToLabel()
        //{
        //    return this.TransactionNo + " : " + TransactionTS.ToString("dd/MM/yyyy");
        //}

        //public virtual void AddState(TransactionState state)
        //{
        //    this.States.Add(state);
        //    this.CurrentState = state;
        //}

        /// <summary>
        /// Transit directly to a state specified in the parameters
        /// </summary>
        /// <param name="transactionState"></param>
        /// <returns></returns>
        //public virtual RuleResult Transit(Context context, ParameterList parameters)
        //{
        //    TransactionStateTransitionParameter transitionPara
        //        = (TransactionStateTransitionParameter)parameters[0].Value;

        //    if (transitionPara.FromState == null)
        //        throw new iSabayaException(Messages.SourceStateIsNotDefined);

        //    if (transitionPara.FromState != this.CurrentState.State)
        //        throw new iSabayaException(Messages.SourceStateIsNotTheCurrentState);

        //    if (transitionPara.ToState == null)
        //        throw new iSabayaException(Messages.DestinationStateIsNotDefined);

        //    if (context.User == null || context.User.Person == null)
        //        throw new iSabayaException(Messages.UserIsInvalid);

        //    RuleResult result;
        //    result = transitionPara.FromState.OnExit(parameters);
        //    if (result.Category == RuleResultCategory.Success)
        //        result = transitionPara.ToState.OnEnter(parameters);

        //    if (null != transitionPara.ToState)
        //        this.CurrentState = new TransactionState(this, transitionPara.ToState,
        //                                    transitionPara.Units, transitionPara.Amount,
        //                                    transitionPara.Reference, transitionPara.Remark,
        //                                    transitionPara.RuleMessage, context.User);

        //    return result;
        //}

        ///// <summary>
        ///// Transit directly to a given TransactionState
        ///// </summary>
        ///// <param name="transactionState"></param>
        ///// <returns></returns>
        //public virtual RuleResult Transit(Context context, TransactionState destinationState)
        //{
        //    if (null == destinationState)
        //        throw new iSabayaException(Messages.DestinationStateIsNotDefined);

        //    RuleResult result;
        //    if ((null == this.CurrentState || null == this.CurrentState.State.OnExitRule)
        //        && null == destinationState.State.OnEnterRule)
        //    {
        //        this.CurrentState = destinationState;
        //        destinationState.Owner = this;
        //        result = RuleResult.Success;
        //    }
        //    else
        //    {
        //        destinationState.Transaction = this;
        //        ParameterList parameters = new ParameterList();
        //        TransactionStateTransitionParameter transitionPara
        //            = new TransactionStateTransitionParameter
        //            {
        //                Amount = destinationState.Amount,
        //                Context = context,
        //                FromState = this.CurrentState == null ? null : this.CurrentState.State,
        //                Reference = destinationState.Reference,
        //                Remark = destinationState.Remark,
        //                Timestamp = DateTime.Now,
        //                ToState = destinationState.State,
        //                Transaction = this,
        //                Units = destinationState.Units,
        //                //User = context.User,
        //            };

        //        parameters.Add(new RuleParameter(ParameterDirection.INOUT, "TransitionParameter",
        //                                            typeof(TransactionStateTransitionParameter),
        //                                            transitionPara
        //                                        )
        //                        );

        //        if (null != this.CurrentState)
        //        {
        //            result = this.CurrentState.OnExit(parameters);
        //            if (result.Category == RuleResultCategory.Success)
        //                result = transitionPara.ToState.OnEnter(parameters);
        //        }
        //        else
        //        {
        //            result = destinationState.OnEnter(parameters);
        //        }

        //        if (null != transitionPara.ToState)
        //            this.CurrentState = new TransactionState(this, transitionPara.ToState,
        //                                        transitionPara.Units, transitionPara.Amount,
        //                                        transitionPara.Reference, transitionPara.Remark,
        //                                        transitionPara.RuleMessage, context.User);
        //    }

        //    return result;
        //}

        ///// <summary>
        ///// Transit from the current state to the state specified by transition
        ///// </summary>
        ///// <param name="stateTransition">Selected transition, must not be null</param>
        ///// <param name="amount">The amount of money to be set to the transaction</param>
        ///// <param name="units">The number of investment units to be set to the transanction</param>
        ///// <param name="transitionTimestamp">The timestamp of the transition</param>
        ///// <param name="reference">The reference, if any</param>
        ///// <param name="remark">The remark, if any</param>
        ///// <param name="executedBy">The user who makes this transition</param>
        ///// <returns></returns>
        //public virtual RuleResult Transit(Context context,
        //                                    TransactionStateCategory toStateCategory,
        //                                    double units, Money amount, String reference,
        //                                    String remark, String message)
        //{
        //    State toState = this.Type.GetState(toStateCategory);

        //    RuleResult result;
        //    if ((null == this.CurrentState || null == this.CurrentState.State.OnExitRule)
        //        && null == toState.OnEnterRule)
        //    {
        //        this.CurrentState = new TransactionState(this, toState, units, amount, reference,
        //                                                    remark, message, context.User);
        //        result = RuleResult.Success;
        //    }
        //    else
        //    {
        //        ParameterList parameters = new ParameterList();
        //        TransactionStateTransitionParameter transitionPara = new TransactionStateTransitionParameter
        //        {
        //            Amount = amount,
        //            FromState = this.CurrentState.State,
        //            Reference = reference,
        //            Remark = remark,
        //            Context = context,
        //            Timestamp = DateTime.Now,
        //            ToState = toState,
        //            Transaction = this,
        //            Units = units,
        //            //User = context.User,
        //        };
        //        parameters.Add(new RuleParameter(ParameterDirection.INOUT, "TransitionParameter",
        //        typeof(TransactionStateTransitionParameter), transitionPara));

        //        if (null != this.CurrentState)
        //        {
        //            result = this.CurrentState.OnExit(parameters);
        //            if (result.Category == RuleResultCategory.Success)
        //                result = toState.OnEnter(parameters);
        //        }
        //        else
        //        {
        //            result = toState.OnEnter(parameters);
        //        }

        //        if (null != transitionPara.ToState)
        //            this.CurrentState = new TransactionState(this, transitionPara.ToState,
        //                                        transitionPara.Units, transitionPara.Amount,
        //                                        transitionPara.Reference, transitionPara.Remark,
        //                                        transitionPara.RuleMessage, context.User);
        //    }

        //    return result;
        //}

        ///// <summary>
        ///// Transit from the current state to the state specified by transition
        ///// </summary>
        ///// <param name="stateTransition">Selected transition, must not be null</param>
        ///// <param name="amount">The amount of money to be set to the transaction</param>
        ///// <param name="units">The number of investment units to be set to the transanction</param>
        ///// <param name="transitionTimestamp">The timestamp of the transition</param>
        ///// <param name="reference">The reference, if any</param>
        ///// <param name="remark">The remark, if any</param>
        ///// <param name="executedBy">The user who makes this transition</param>
        ///// <returns></returns>
        //public virtual RuleResult Transit(Context context, StateTransition transition,
        //                                    Money amount, double units, DateTime transitionTimestamp,
        //                                    String reference, String remark)
        //{
        //    if (transition == null)
        //        throw new iSabayaException(Messages.TransitionIsNotDefined);
        //    if (null == transition.ToState)
        //        throw new iSabayaException(Messages.DestinationStateIsNotDefined);
        //    if (transition.FromState != this.CurrentState.State)
        //        throw new iSabayaException(Messages.SourceStateIsNotTheCurrentState);

        //    ParameterList parameters = new ParameterList();
        //    TransactionStateTransitionParameter transitionPara = new TransactionStateTransitionParameter
        //    {
        //        Amount = amount,
        //        FromState = transition.FromState,
        //        Reference = reference,
        //        Remark = remark,
        //        Context = context,
        //        Timestamp = DateTime.Now,
        //        ToState = transition.ToState,
        //        Transaction = this,
        //        Units = units,
        //    };
        //    parameters.Add(new RuleParameter(ParameterDirection.INOUT, "TransitionParameter",
        //    typeof(TransactionStateTransitionParameter), transitionPara));

        //    RuleResult result;

        //    result = transition.PreTransit(parameters);
        //    if (result.Category == RuleResultCategory.Success)
        //    {
        //        result = transition.Transit(parameters);
        //        if (result.Category == RuleResultCategory.Success)
        //            result = transition.ToState.OnEnter(parameters);
        //    }
        //    if (null != transitionPara.ToState)
        //        this.CurrentState = new TransactionState(this, transitionPara.ToState,
        //                                    transitionPara.Units, transitionPara.Amount,
        //                                    transitionPara.Reference, transitionPara.Remark,
        //                                    transitionPara.RuleMessage, context.User);
        //    return result;
        //}

        public override void Save(Context context)
        {
            if (null != this.ExecuteBeforeSave)
            {
                this.ExecuteBeforeSave(context, this);
            }

            bool isNewTransaction = base.ID == 0;

            bool requireExtraUpdate;

            if (null == this.CurrentState)
            {
                requireExtraUpdate = false;
            }
            else
            {
                requireExtraUpdate = isNewTransaction && this.CurrentState.TransactionStateID == 0;
            }

            //this.CurrentState and/or this.accountBalance may be newly created object
            //(TransactionStateID and/or this.AccountBalanceID are 0).
            //In such case we will have to update this transaction later.
            if (base.ID == 0)
            {
                context.Persist(this); //Get TransactionID
            }
            //Save children transaction
            int seqNo = -1;

            foreach (TransactionRelation r in this.Children)
            {
                //r.Child.States = null;
                r.SeqNo  = ++seqNo;
                r.Parent = this;
                r.Child.Save(context);
                r.Save(context);
            }

            //this.CurrentState is saved as part of this.states
            if (this.States != null)
            {
                foreach (TransactionState s in this.States)
                {
                    //begin bug avoidance : the hibernate-generated proxy inserted null if states contains none
                    if (null == s)
                    {
                        continue;
                    }
                    //end bug avoidance

                    //s.Transaction = this;
                    s.Save(context);
                }
            }

            if (this.payments != null)
            {
                foreach (TransactionPayment p in this.payments)
                {
                    p.Transaction = this;
                    p.Save(context);
                }
            }

            //if (null != this.Fund && this.Fund.IsToBeSaved)
            //{
            //    this.Fund.IsToBeSaved = false;
            //    this.Fund.Save(context);
            //}

            context.PersistenceSession.Update(this);

            if (null != this.ExecuteAfterSave)
            {
                this.ExecuteAfterSave(context, this);
            }

            //context.PersistenceSession.Flush();
        }
Ejemplo n.º 27
0
 public virtual void Save(Context context)
 {
     Payment.Save(context);
     context.Persist(this);
 }
Ejemplo n.º 28
0
 public override void Persist(Context context)
 {
     //base.Persist(context);
     context.Persist(this);
 }
Ejemplo n.º 29
0
 public virtual void Save(Context context)
 {
     context.Persist(this);
 }