Example #1
0
        public TListResponse Process(IDbConnection connection, TListRequest request)
        {
            StateBag.Clear();

            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            Connection = connection;
            Request    = request;
            ValidateRequest();

            Response          = new TListResponse();
            Response.Entities = new List <TRow>();

            Row = new TRow();

            var query = CreateQuery();

            this.Query = query;

            PrepareQuery(query);

            ApplyKeyOrder(query);

            query.ApplySkipTakeAndCount(request.Skip, request.Take, request.ExcludeTotalCount);

            ApplyContainsText(query, request.ContainsText);

            ApplySort(query);

            ApplyFilters(query);

            OnBeforeExecuteQuery();

            Response.TotalCount = query.ForEach(Connection, delegate()
            {
                var clone = ProcessEntity(Row.Clone());

                if (clone != null)
                {
                    Response.Entities.Add(clone);
                }
            });

            Response.SetSkipTakeTotal(query);

            OnAfterExecuteQuery();

            OnReturn();

            return(Response);
        }
Example #2
0
        public TSaveResponse Process(IUnitOfWork unitOfWork, TSaveRequest request,
                                     SaveRequestType requestType = SaveRequestType.Auto)
        {
            StateBag.Clear();

            if (unitOfWork == null)
            {
                throw new ArgumentNullException("unitOfWork");
            }

            UnitOfWork = unitOfWork;

            Request  = request;
            Response = new TSaveResponse();

            Row = request.Entity;
            if (Row == null)
            {
                throw new ArgumentNullException("Entity");
            }

            if (requestType == SaveRequestType.Auto)
            {
                if (Row.IdField[Row] == null)
                {
                    requestType = SaveRequestType.Create;
                }
                else
                {
                    requestType = SaveRequestType.Update;
                }
            }

            if (requestType == SaveRequestType.Update)
            {
                ValidateAndClearIdField();
                Old = new TRow();
                LoadOldEntity();
            }

            ValidateRequest();
            SetInternalFields();
            BeforeSave();

            ClearNonTableAssignments();
            ExecuteSave();

            AfterSave();

            PerformAuditing();

            OnReturn();
            return(Response);
        }
Example #3
0
        public TDeleteResponse Process(IUnitOfWork unitOfWork, TDeleteRequest request)
        {
            StateBag.Clear();

            if (unitOfWork == null)
            {
                throw new ArgumentNullException("unitOfWork");
            }

            ValidatePermissions();

            UnitOfWork = unitOfWork;

            Request  = request;
            Response = new TDeleteResponse();

            if (request.EntityId == null)
            {
                throw DataValidation.RequiredError("EntityId");
            }

            Row = new TRow();

            var idField = (Field)Row.IdField;

            LoadEntity();

            ValidateRequest();

            var isDeletedRow = Row as IIsActiveDeletedRow;
            var deleteLogRow = Row as IDeleteLogRow;

            if ((isDeletedRow != null &&
                 isDeletedRow.IsActiveField[Row] < 0) ||
                (deleteLogRow != null &&
                 !((Field)deleteLogRow.DeleteUserIdField).IsNull(Row)))
            {
                Response.WasAlreadyDeleted = true;
            }
            else
            {
                OnBeforeDelete();

                ExecuteDelete();

                OnAfterDelete();

                DoAudit();
            }

            OnReturn();

            return(Response);
        }
 // Implement the SaveViewState method. If the StateBag
 // that stores the MyItem class's view state contains
 // a value for the message property and if the value
 // has changed since the TrackViewState method was last
 // called, all view state for this class is deleted,
 // using the StateBag.Clear method,and the new value is added.
 object IStateManager.SaveViewState()
 {
     // Check whether the message property exists in
     // the ViewState property, and if it does, check
     // whether it has changed since the most recent
     // TrackViewState method call.
     if (!((IDictionary)_viewstate).Contains("message") || _viewstate.IsItemDirty("message"))
     {
         _viewstate.Clear();
         // Add the _message property to the StateBag.
         _viewstate.Add("message", _message);
     }
     return(((IStateManager)_viewstate).SaveViewState());
 }
        public TSaveResponse Process(IUnitOfWork unitOfWork, TSaveRequest request,
                                     SaveRequestType requestType = SaveRequestType.Auto)
        {
            StateBag.Clear();

            UnitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
            Request    = request ?? throw new ArgumentNullException(nameof(request));

            Response = new TSaveResponse();

            Row = (request.Entity ?? throw new ArgumentNullException(nameof(request.Entity))).Clone();

            if (requestType == SaveRequestType.Auto)
            {
                if (Row.IdField.IsNull(Row))
                {
                    requestType = SaveRequestType.Create;
                }
                else
                {
                    requestType = SaveRequestType.Update;
                }
            }

            if (requestType == SaveRequestType.Update)
            {
                ValidateAndClearIdField();
                Old = new TRow();
                LoadOldEntity();
            }
            else
            {
                Old = null;
            }

            ValidateRequest();
            SetInternalFields();
            BeforeSave();

            ClearNonTableAssignments();
            ExecuteSave();

            AfterSave();

            PerformAuditing();

            OnReturn();
            return(Response);
        }
Example #6
0
        public void Deny_Unrestricted()
        {
            StateBag bag = new StateBag(true);

            Assert.IsNotNull(bag.Add("key", "value"), "Add");
            Assert.AreEqual(1, bag.Count, "Count");
            Assert.IsNotNull(bag.GetEnumerator(), "GetEnumerator");
            bag.SetItemDirty("key", true);
            Assert.IsTrue(bag.IsItemDirty("key"), "IsItemDirty");
            bag.Remove("key");

            bag.Clear();
            bag["key"] = "value";
            Assert.IsNotNull(bag["key"], "this[string]");
            Assert.IsNotNull(bag.Keys, "Keys");
            Assert.IsNotNull(bag.Values, "Values");
            bag.SetDirty(true);
        }
Example #7
0
        public void IDictionary_Deny_Unrestricted()
        {
            IDictionary d = new StateBag();

            d.Add("key", "value");
            Assert.IsTrue(d.Contains("key"), "Contains");
            Assert.AreEqual(1, d.Count, "Count");
            d.Remove("key");
            d["key"] = "value";
            Assert.AreEqual("value", d["key"], "this[string]");
            d.Clear();
            Assert.IsFalse(d.IsFixedSize, "IsFixedSize");
            Assert.IsFalse(d.IsReadOnly, "IsReadOnly");

            ICollection c = (d as ICollection);

            Assert.IsFalse(c.IsSynchronized, "IsSynchronized");
            Assert.IsNotNull(c.SyncRoot, "SyncRoot");
        }
Example #8
0
        public TRetrieveResponse Process(IDbConnection connection, TRetrieveRequest request)
        {
            StateBag.Clear();

            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            request.CheckNotNull();
            if (request.EntityId == null)
            {
                throw DataValidation.RequiredError("entityId");
            }

            Connection = connection;
            Request    = request;
            ValidateRequest();

            Response = new TRetrieveResponse();
            Row      = new TRow();

            this.Query = CreateQuery();

            PrepareQuery(Query);

            OnBeforeExecuteQuery();

            if (Query.GetFirst(Connection))
            {
                Response.Entity = Row;
            }
            else
            {
                throw DataValidation.EntityNotFoundError(Row, request.EntityId);
            }

            OnAfterExecuteQuery();

            OnReturn();
            return(Response);
        }
        public TDeleteResponse Process(IUnitOfWork unitOfWork, TDeleteRequest request)
        {
            StateBag.Clear();
            UnitOfWork = unitOfWork ?? throw new ArgumentNullException("unitOfWork");
            Request = request;
            Response = new TDeleteResponse();

            if (request.EntityId == null)
                throw DataValidation.RequiredError(nameof(request.EntityId), Localizer);

            Row = new TRow();

            LoadEntity();
            ValidatePermissions();
            ValidateRequest();

            var isActiveDeletedRow = Row as IIsActiveDeletedRow;
            var isDeletedRow = Row as IIsDeletedRow;
            var deleteLogRow = Row as IDeleteLogRow;

            if ((isDeletedRow != null && isDeletedRow.IsDeletedField[Row] == true) ||
                (isActiveDeletedRow != null && isActiveDeletedRow.IsActiveField[Row] < 0) ||
                (deleteLogRow != null && !deleteLogRow.DeleteUserIdField.IsNull(Row)))
                Response.WasAlreadyDeleted = true;
            else
            {
                OnBeforeDelete();

                ExecuteDelete();

                OnAfterDelete();

                DoAudit();
            }

            OnReturn();

            return Response;
        }
Example #10
0
        public TListResponse Process(IDbConnection connection, TListRequest request)
        {
            StateBag.Clear();

            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            Connection = connection;
            Request    = request;
            ValidateRequest();

            Response          = new TListResponse();
            Response.Entities = new List <TRow>();

            Row = new TRow();

            var query = CreateQuery();

            this.Query = query;

            DistinctFields = GetDistinctFields();
            if (DistinctFields != null)
            {
                Response.Values = new List <object>();
            }

            PrepareQuery(query);

            if (DistinctFields == null)
            {
                ApplyKeyOrder(query);
            }

            query.ApplySkipTakeAndCount(request.Skip, request.Take,
                                        request.ExcludeTotalCount || DistinctFields != null);

            ApplyContainsText(query, request.ContainsText);

            if (DistinctFields == null)
            {
                ApplySort(query);
            }

            ApplyFilters(query);

            OnBeforeExecuteQuery();

            if (DistinctFields == null || DistinctFields.Length > 0)
            {
                Response.TotalCount = query.ForEach(Connection, delegate()
                {
                    var clone = ProcessEntity(Row.Clone());

                    if (clone != null)
                    {
                        if (DistinctFields != null)
                        {
                            foreach (var field in DistinctFields)
                            {
                                Response.Values.Add(field.AsObject(clone));
                            }
                        }
                        else
                        {
                            Response.Entities.Add(clone);
                        }
                    }
                });
            }
            else
            {
                // mark response to specify that one or more fields are invalid
                Response.Values = null;
            }

            Response.SetSkipTakeTotal(query);

            OnAfterExecuteQuery();

            OnReturn();

            return(Response);
        }
 public void Clear()
 {
     viewState.Clear();
 }