Beispiel #1
0
        public static bool Delete(Entities.TourCostRule rule)
        {
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    if (repo.Delete(rule))
                    {
                        ts.Complete();
                        rules.Remove(rule);

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    DomainModel.Application.Status.Update(
                        StatusController.Abstract.StatusTypes.Error,
                        "",
                        ex.Message);
                }
                catch { }
            }

            return(false);
        }
Beispiel #2
0
 internal static void Load(Entities.TourCostRule rule)
 {
     // Load rule constraint properties
     constraints.LoadByRule(rule);
     foreach (TourCostRuleConstraint constraint in rule.Constraints)
     {
         properties.LoadByConstraint(constraint);
     }
 }
Beispiel #3
0
        public void CopyTo(TourCostRule rule)
        {
            rule.Id          = this.Id;
            rule.Name        = this.Name;
            rule.IsPerPerson = this.IsPerPerson;

            this.constraints.CopyTo(rule.Constraints);
            this.Formula.CopyTo(rule.Formula);
            this.DeletedConstraints.CopyTo(rule.DeletedConstraints);

            rule.IsDirty = this.IsDirty;
        }
Beispiel #4
0
        public static bool Save(Entities.TourCostRule rule)
        {
            bool res;

            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    if (rule.Id >= 0)
                    {
                        res = repo.Update(rule);
                    }
                    else
                    {
                        res = repo.Insert(rule);
                        if (res)
                        {
                            rules.Add(rule);
                        }
                    }

                    // Load rule constraint properties
                    res = DomainModel.TourRuleConstraints.Save(rule);

                    if (res)
                    {
                        ts.Complete();
                        rule.DeletedConstraints.Clear();
                    }
                    else
                    {
                        rule.DeletedConstraints.UndoDelet(rule.Constraints);
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    DomainModel.Application.Status.Update(
                        StatusController.Abstract.StatusTypes.Error,
                        "",
                        ex.Message);
                }
                catch { }

                res = false;
            }

            return(res);
        }
Beispiel #5
0
        internal static bool Save(Entities.TourCostRule rule)
        {
            bool res = true;

            try
            {
                // Note: Only is called from inside a transaction
                //using (TransactionScope ts = new TransactionScope())
                //{
                foreach (TourCostRuleConstraint constraint in rule.Constraints)
                {
                    if (constraint.IsDirty)
                    {
                        if (constraint.Id < 0)
                        {
                            if (!(res = constraints.Insert(rule, constraint)))
                            {
                                break;
                            }
                        }
                        else
                        {
                            if (!(res = constraints.Update(rule, constraint)))
                            {
                                break;
                            }
                        }
                    }

                    foreach (TourCostRuleConstraintProperty property in constraint.Properties)
                    {
                        if (property.IsDirty)
                        {
                            if (property.Id < 0)
                            {
                                if (!(res = properties.Insert(constraint, property)))
                                {
                                    break;
                                }
                            }
                            else
                            {
                                if (!(res = properties.Update(constraint, property)))
                                {
                                    break;
                                }
                            }
                        }
                    }

                    if (!res)
                    {
                        break;
                    }
                }

                foreach (TourCostRuleConstraint constraint in rule.DeletedConstraints)
                {
                    if (!(res = constraints.Delete(constraint)))
                    {
                        break;
                    }
                }

                /*
                 *  if (res)
                 *  {
                 *      ts.Complete();
                 *  }*/
                //}
            }
            catch (Exception ex)
            {
                res = false;
            }

            return(res);
        }