Example #1
0
        public DataResult Delete(params IEntity[] instances)
        {
            var result = DataResult.BuildSuccess();

            foreach (var instance in instances)
            {
                var one = instance as Entity;

                // AllowExecuteWithoutPrimaryKeys
                if (!one.__AllowExecuteWithoutPrimaryKeys)
                {
                    result.InnerResults.Add(new DataResult()
                    {
                        Success = false,
                        Message =
                            new[] {
                            instance.__EntityFullName,
                            " (",
                            instance.__TitleValue,
                            ") ",
                            " not allow to delete ",
                            "without primary keys.",
                        }.Join(),
                    });
                    continue;
                }

                // Removable
                if (!instance.__Removable)
                {
                    result.InnerResults.Add(new DataResult()
                    {
                        Success = false,
                        Message =
                            new[] {
                            "Not allow to delete: ",
                            instance.__TitleValue,
                        }.Join(),
                    });
                    continue;
                }

                // BeforeRemove
                if (null != one)
                {
                    var r = new DataResult();
                    one.InvokeBeforeRemove(r);
                    if (!r.Success)
                    {
                        r.Message = new[] {
                            "BeforeRemove return failure: ",
                            instance.__TitleValue,
                        }.Join();
                        result.InnerResults.Add(r);
                        continue;
                    }
                }

                // Execute
                var exeResult = base.Delete(
                    instance.__TableName,
                    instance.__KeyColumnNameValues
                    );
                result.InnerResults.Add(exeResult);

                // AfterRemove
                if (null != one)
                {
                    var r = new DataResult();
                    one.InvokeAfterRemove(r);
                    if (!r.Success)
                    {
                        r.Message = new[] {
                            "AfterRemove return failure: ",
                            instance.__TitleValue,
                        }.Join();
                        result.InnerResults.Add(r);
                        continue;
                    }
                }
            }
            return(result);
        }
Example #2
0
        public DataResult Insert(params IEntity[] instances)
        {
            var result = DataResult.BuildSuccess();

            foreach (var instance in instances)
            {
                var one = instance as Entity;

                // Addable
                if (!instance.__Addable)
                {
                    result.InnerResults.Add(new DataResult()
                    {
                        Success = false,
                        Message =
                            new[] {
                            "Not allow to insert: ",
                            instance.__TitleValue,
                        }.Join(),
                    });
                    continue;
                }

                // BeforeAdd
                if (null != one)
                {
                    var r = new DataResult();
                    one.InvokeBeforeAdd(r);
                    if (!r.Success)
                    {
                        r.Message = new[] {
                            "BeforeAdd return failure: ",
                            instance.__TitleValue,
                        }.Join();
                        result.InnerResults.Add(r);
                        continue;
                    }
                }

                // Execute
                var insertR = base.Insert(
                    instance.__TableName,
                    instance.__ColumnNameValues
                    );
                result.InnerResults.Add(insertR);


                // AfterAdd
                if (null != one)
                {
                    var r = new DataResult();
                    one.InvokeAfterAdd(r);
                    if (!r.Success)
                    {
                        r.Message = new[] {
                            "AfterAdd return failure: ",
                            instance.__TitleValue,
                        }.Join();
                        result.InnerResults.Add(r);
                        continue;
                    }
                }
            }
            return(result);
        }