コード例 #1
0
        /*
         *
         * This method handles all the grid operations
         */
        protected async Task UpdateGridAsync <Dto, Entity>(DataPayLoad payLoad) where Dto : class
            where Entity : class
        {
            GridOperationHandler <Dto> gridOperationHandler = new GridOperationHandler <Dto>(DataServices);
            IEnumerable <Dto>          dtoValues            = payLoad.RelatedObject as IEnumerable <Dto>;

            // ok now we can see if it is an insert or a delete.
            try
            {
                if (dtoValues != null)
                {
                    var newItems = dtoValues.Where(x =>
                    {
                        BaseViewObject baseViewObject = x as BaseViewObject;
                        return(baseViewObject.IsNew == true);
                    });
                    if (newItems.Any())
                    {
                        await gridOperationHandler.ExecuteInsertAsync <Entity>(newItems).ConfigureAwait(false);
                    }

                    var itemsToDelete = dtoValues.Where(x =>
                    {
                        BaseViewObject baseViewObject = x as BaseViewObject;
                        return(baseViewObject.IsDeleted == true);
                    });
                    if (itemsToDelete.Count() > 0)
                    {
                        await gridOperationHandler.ExecuteDeleteAsync <Entity>(itemsToDelete).ConfigureAwait(false);
                    }
                    var updateItems = dtoValues.Where(x =>
                    {
                        BaseViewObject baseViewObject = x as BaseViewObject;
                        return((baseViewObject.IsDirty == true) && (baseViewObject.IsNew == false));
                    });
                    if (updateItems.Count() > 0)
                    {
                        await gridOperationHandler.ExecuteUpdateAsync <Entity>(updateItems).ConfigureAwait(false);
                    }
                    for (int i = 0; i < updateItems.Count(); ++i)
                    {
                        BaseViewObject baseViewObject = updateItems.ElementAt(i) as BaseViewObject;
                        if (baseViewObject != null)
                        {
                            baseViewObject.IsNew   = false;
                            baseViewObject.IsDirty = false;
                        }
                    }
                }
            } catch (Exception e)
            {
                /// FIXME: in case of exception happens that gets called twice.
                var msg = "UpdateGridException " + e.Message;
                throw new DataLayerException(msg);
            }
        }
コード例 #2
0
        protected async Task <bool> DeleteGridAsync <Dto, Entity>(DataPayLoad payLoad) where Dto : class
            where Entity : class
        {
            bool retValue = false;
            GridOperationHandler <Dto> gridOperationHandler = new GridOperationHandler <Dto>(DataServices);
            IEnumerable <Dto>          dtoValues            = payLoad.RelatedObject as IEnumerable <Dto>;

            if (dtoValues != null)
            {
                var toBeDeleted = dtoValues.Where(x =>
                {
                    BaseViewObject baseViewObject = x as BaseViewObject;
                    return(baseViewObject.IsDeleted == true);
                });
                if (toBeDeleted.Count() > 0)
                {
                    retValue = await gridOperationHandler.ExecuteDeleteAsync <Dto>(toBeDeleted);
                }
            }
            return(retValue);
        }