Exemplo n.º 1
0
        public static string GetOperationLog(this RoleGroupDTO entity, RoleGroupDTO oldDTO = null)
        {
            var sb = new StringBuilder();

            if (oldDTO == null)
            {
                sb.AppendLine(string.Format("{0}: {1}", CommonMessageResources.Name, entity.Name));
                sb.AppendLine(string.Format("{0}: {1}", CommonMessageResources.Description, entity.Description));
                sb.AppendLine(string.Format("{0}: {1}", CommonMessageResources.SortOrder, entity.SortOrder));
            }
            else
            {
                if (entity.Name != oldDTO.Name)
                {
                    sb.AppendLine(string.Format("{0}: {1} => {2}",
                                                CommonMessageResources.Name, oldDTO.Name, entity.Name));
                }
                if (entity.Description != oldDTO.Description)
                {
                    sb.AppendLine(string.Format("{0}: {1} => {2}",
                                                CommonMessageResources.Description, oldDTO.Description, entity.Description));
                }
                if (entity.SortOrder != oldDTO.SortOrder)
                {
                    sb.AppendLine(string.Format("{0}: {1} => {2}",
                                                CommonMessageResources.SortOrder, oldDTO.SortOrder, entity.SortOrder));
                }
            }

            return(sb.ToString().TrimEnd('\r', '\n'));
        }
Exemplo n.º 2
0
        public RoleGroupDTO Add(RoleGroupDTO roleGroupDTO)
        {
            var roleGroup = roleGroupDTO.ToModel();

            roleGroup.Id      = IdentityGenerator.NewSequentialGuid();
            roleGroup.Created = DateTime.UtcNow;

            if (roleGroup.Name.IsNullOrBlank())
            {
                throw new DefinedException(UserSystemMessagesResources.Name_Empty);
            }

            if (_Repository.Exists(roleGroup))
            {
                throw new DataExistsException(string.Format(UserSystemMessagesResources.RoleGroup_Exists_WithValue, roleGroup.Name));
            }

            _Repository.Add(roleGroup);

            #region 操作日志

            var roleGroupDto = roleGroup.ToDto();

            OperateRecorder.RecordOperation(roleGroupDto.Id.ToString(),
                                            UserSystemMessagesResources.Add_RoleGroup,
                                            roleGroupDto.GetOperationLog());

            #endregion

            //commit the unit of work
            _Repository.UnitOfWork.Commit();

            return(roleGroup.ToDto());
        }
Exemplo n.º 3
0
        public void Update(RoleGroupDTO roleGroupDTO)
        {
            //get persisted item
            var persisted = _Repository.Get(roleGroupDTO.Id);

            if (persisted != null) //if customer exist
            {
                var current = roleGroupDTO.ToModel();
                current.Created = persisted.Created;    //不修改创建时间

                if (current.Name.IsNullOrBlank())
                {
                    throw new DataExistsException(UserSystemResource.Common_Name_Empty);
                }

                if (_Repository.Exists(current))
                {
                    throw new DataExistsException(UserSystemResource.RoleGroup_Exists);
                }

                //Merge changes
                _Repository.Merge(persisted, current);

                //commit unit of work
                _Repository.UnitOfWork.Commit();
            }
            else
            {
                // Not Exists
            }
        }
Exemplo n.º 4
0
        public IHttpActionResult Create([FromBody] RoleGroupDTO roleGroup)
        {
            ThrowIfUserHasNoRole(createRole);
            if (roleGroup == null)
            {
                throw new KairosException("Missing model parameter");
            }

            if (roleGroup.RoleGroup_PK != 0)
            {
                throw new KairosException("Post method is not allowed because the requested primary key is must be '0' (zero) .");
            }
            using (var roleGroupCreateHandler = new RoleGroupCreateHandler(Db, ActiveUser, new RoleGroupValidator(), new RoleGroupFactory(Db, ActiveUser), new RoleGroupQuery(Db), AccessControl))
            {
                using (var transaction = new TransactionScope())
                {
                    var saveResult = roleGroupCreateHandler.Save(roleGroupDTO: roleGroup, dateStamp: DateTime.Now);
                    transaction.Complete();
                    if (saveResult.Success)
                    {
                        return(Ok(new SuccessResponse(saveResult.Model, saveResult.Message)));
                    }
                    return(Ok(new ErrorResponse(ServiceStatusCode.ValidationError, saveResult.ValidationResult, saveResult.Message)));
                }
            }
        }
 public void Update(RoleGroupDTO roleGroupDTO, DateTime dateStamp)
 {
     if (roleGroupDTO == null)
     {
         throw new ArgumentNullException("RoleGroup model is null.");
     }
     tblM_RoleGroup roleGroup = roleGroupFactory.CreateFromDbAndUpdateFromDTO(roleGroupDTO, dateStamp);
 }
Exemplo n.º 6
0
        public tblM_RoleGroup Insert(RoleGroupDTO roleGroupDTO, DateTime dateStamp)
        {
            if (roleGroupDTO == null)
            {
                throw new ArgumentNullException("RoleGroup model is null.");
            }
            tblM_RoleGroup roleGroup = roleGroupFactory.CreateFromDTO(roleGroupDTO, dateStamp);

            return(Db.tblM_RoleGroup.Add(roleGroup));
        }
Exemplo n.º 7
0
        public static string GetOperationLogForUpdateUser(this RoleGroupDTO entity, List <User> users)
        {
            var sb = new StringBuilder();

            users = users ?? new List <User>();
            sb.AppendLine(string.Format("{0}:{1}{2}", UserSystemMessagesResources.User, Environment.NewLine,
                                        string.Join(Environment.NewLine, users.Select(x => string.Format("{0}({1})", x.Name, x.LoginName)))));

            return(sb.ToString().TrimEnd('\r', '\n'));
        }
        private RoleGroupEntryModel GetCreateStateModel()
        {
            RoleGroupEntryFormData formData     = new RoleGroupEntryFormData();
            List <Control>         formControls = CreateFormControls(0);
            RoleGroupDTO           roleGroupDTO = new RoleGroupDTO();

            return(new RoleGroupEntryModel()
            {
                FormData = formData,
                FormControls = formControls,
                Model = new RoleGroupDTO(),
            });
        }
Exemplo n.º 9
0
 //int roleGroupID { set; get; }
 public frmRoleGroup(int roleGroupID)
 {
     InitializeComponent();
     if (roleGroupID != 0)
     {
         Message = bizRoleSecurity.GetRoleGroup(roleGroupID);
     }
     else
     {
         Message = new RoleGroupDTO();
     }
     SetRoles();
     ShowMessage();
 }
        private RoleGroupEntryModel GetUpdateStateModel(int roleGroupPK)
        {
            RoleGroupEntryFormData formData     = new RoleGroupEntryFormData();
            List <Control>         formControls = CreateFormControls(roleGroupPK);
            RoleGroupDTO           roleGroupDTO = roleGroupQuery.GetByPrimaryKey(roleGroupPK);

            if (roleGroupDTO == null)
            {
                throw new KairosException($"Record with primary key '{roleGroupDTO.RoleGroup_PK}' is not found.");
            }

            return(new RoleGroupEntryModel()
            {
                FormData = formData,
                FormControls = formControls,
                Model = roleGroupDTO,
            });
        }
Exemplo n.º 11
0
        public ActionResult EditGroup(RoleGroupDTO roleGroup)
        {
            if (roleGroup.Id == Guid.Empty)
            {
                _roleGroupService.Add(roleGroup);
            }
            else
            {
                _roleGroupService.Update(roleGroup);
            }

            return(Json(new AjaxResponse
            {
                Succeeded = true,
                ShowMessage = false,
                RedirectUrl = Url.Action("Index")
            }));
        }
Exemplo n.º 12
0
        public void Update(RoleGroupDTO roleGroupDTO)
        {
            var group = _Repository.Get(roleGroupDTO.Id);

            if (group == null)
            {
                throw new DataNotFoundException(UserSystemMessagesResources.RoleGroup_NotExists);
            }

            var oldDTO = group.ToDto();

            var current = roleGroupDTO.ToModel();

            group.Name        = current.Name;
            group.Description = current.Description;
            group.SortOrder   = current.SortOrder;

            if (group.Name.IsNullOrBlank())
            {
                throw new DefinedException(UserSystemMessagesResources.Name_Empty);
            }

            if (_Repository.Exists(group))
            {
                throw new DataExistsException(string.Format(UserSystemMessagesResources.RoleGroup_Exists_WithValue, group.Name));
            }

            #region 操作日志

            var groupDto = group.ToDto();

            OperateRecorder.RecordOperation(oldDTO.Id.ToString(),
                                            UserSystemMessagesResources.Update_RoleGroup,
                                            groupDto.GetOperationLog(oldDTO));

            #endregion

            //commit unit of work
            _Repository.UnitOfWork.Commit();
        }
        public ActionResult EditGroup(RoleGroupDTO roleGroup)
        {
            return(HttpHandleExtensions.AjaxCallGetResult(() =>
            {
                if (roleGroup.Id == Guid.Empty)
                {
                    _roleGroupService.Add(roleGroup);
                    this.JsMessage = MessagesResources.Add_Success;
                }
                else
                {
                    _roleGroupService.Update(roleGroup);
                    this.JsMessage = MessagesResources.Update_Success;
                }

                return Json(new AjaxResponse
                {
                    Succeeded = true,
                    RedirectUrl = Url.Action("Index")
                });
            }));
        }
        public SaveResult <RoleGroupEntryModel> Save(RoleGroupDTO roleGroupDTO, DateTime dateStamp)
        {
            ModelValidationResult validationResult = roleGroupValidator.Validate(roleGroupDTO);
            bool success = false;
            RoleGroupEntryModel model = null;

            if (validationResult.IsValid)
            {
                success = true;
                Update(roleGroupDTO, dateStamp);
                Db.SaveChanges();
                model = roleGroupEntryDataProvider.Get(roleGroupDTO.RoleGroup_PK);
            }

            return(new SaveResult <RoleGroupEntryModel>
            {
                Success = success,
                Message = validationResult.IsValid ? "Data successfully updated." : "Validation error occured.",
                Model = model,
                ValidationResult = validationResult
            });
        }
Exemplo n.º 15
0
        public RoleGroupDTO Add(RoleGroupDTO roleGroupDTO)
        {
            var roleGroup = roleGroupDTO.ToModel();

            roleGroup.Id      = IdentityGenerator.NewSequentialGuid();
            roleGroup.Created = DateTime.UtcNow;

            if (roleGroup.Name.IsNullOrBlank())
            {
                throw new DataExistsException(UserSystemResource.Common_Name_Empty);
            }

            if (_Repository.Exists(roleGroup))
            {
                throw new DataExistsException(UserSystemResource.RoleGroup_Exists);
            }

            _Repository.Add(roleGroup);

            //commit the unit of work
            _Repository.UnitOfWork.Commit();

            return(roleGroup.ToDto());
        }
        public RoleGroupDTO GetByPrimaryKey(int primaryKey)
        {
            RoleGroupDTO record = GetQuery().FirstOrDefault(roleGroup => roleGroup.RoleGroup_PK == primaryKey);

            return(record);
        }
Exemplo n.º 17
0
 public static RoleGroup ToModel(this RoleGroupDTO dto)
 {
     return(Mapper.Map <RoleGroup>(dto));
 }