Exemple #1
0
        public BusinessResult <bool> Add(Person model)
        {
            BusinessBase <bool> add = new BusinessBase <bool>(logger);

            Func <bool> onBeforeExecute = () =>
            {
                var result = repository.Any(x => x.Name.Equals(model.Name) && x.RecordStatusId == RecordStatus.Exist);
                if (result)
                {
                    add.Result.Message = new BusinessMessage("اطلاعات تکراری", "شخص وارد شده تکراری می باشد.", MessageType.Error);
                    return(false);
                }

                return(true);
            };

            Func <bool> onExecute = () =>
            {
                SetOrderItems(false, model);

                model.UserId         = (Thread.CurrentPrincipal.Identity as Identity).Id;
                model.RecordStatusId = RecordStatus.Exist;
                model.CreateDate     = repository.GetDateTime();

                return(repository.Add(model));
            };

            add.Execute(onBeforeExecute, onExecute, null);
            if (add.Result.IsOnExecute)
            {
                add.Result.Data    = true;
                add.Result.Message = new BusinessMessage("افزودن اطلاعات", "عملیات افزودن با موفقیت انجام شد.", MessageType.Information);
            }

            return(add.Result);
        }