Beispiel #1
0
 protected virtual void XPOExecute(Action <XpoDatabase, Session> work, bool transactional = true)
 {
     _Database.Execute(work, transactional);
 }
Beispiel #2
0
        public override IDataValidationResults <TKey> Create(IEnumerable <TModel> items)
        {
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }
            IDataValidationResults <TKey> result = new DataValidationResults <TKey>();

            try
            {
                result = xpo.Execute((db, w) =>
                {
                    var r = new DataValidationResults <TKey>();
                    foreach (var item in items)
                    {
                        val?.Inserting(item, r);

                        //bool ok = val.Inserting(item);
                        //if (!ok)
                        //	throw new Exception(String.Format("Validator failed on Inserting on '{0}'", XpoType.Name));

                        var newItem = Assign(item, Activator.CreateInstance(typeof(TXPOClass), new object[] { w }) as TXPOClass);
                        //TODO: Move to Validator Inserted
                        //newItem.AddStampUTC = DateTime.UtcNow;
                        //newItem.ModStampUTC = DateTime.UtcNow;

                        //ok = val.Inserted(item, newItem);
                        //if (!ok)
                        //	throw new Exception(String.Format("Validator failed on Inserted on '{0}'", XpoType.Name));
                        //w.FailedCommitTransaction += (s, e) =>
                        //{

                        //	e.Handled = true;
                        //};
                        try
                        {
                            w.CommitTransaction();
                            item.ID = newItem.ID;
                            val?.Inserted(item, newItem, r);
                        }
                        catch (Exception e)
                        {
                            r.Add(new DataValidationResult <TKey>
                            {
                                ResultType = DataValidationResultType.Error,
                                Message    = e.InnerException != null ? e.InnerException.Message : e.Message
                            });
                        }
                    }
                    return(r);
                });
            }
            catch (Exception ex)
            {
                result.Add(new DataValidationResult <TKey>
                {
                    ResultType = DataValidationResultType.Error,
                    Message    = ex.InnerException != null ? ex.InnerException.Message : ex.Message
                });
            }
            return(result);
        }