Ejemplo n.º 1
0
        public void CreateRole(VM.RoleItemModel role)
        {
            MessageModel message = null;

            if (role == null)
            {
                message = new MessageModel()
                {
                    IsSuccess = false, Message = MessageResource.Role_Empty_ErrorMessage + "," + MessageResource.Message_CommonUpdateFail, MessageType = MessageType.InsertFailure
                };
                return;
            }
            if (ctx.Common_Authen_Role.Any(i => i.RoleName == role.RoleName))
            {
                message = new MessageModel()
                {
                    IsSuccess = false, MessageType = MessageType.InsertFailure, Message = MessageResource.Role_Exits_ErrorMessage + "," + MessageResource.Message_CommonUpdateFail
                };
                return;
            }

            var maxId  = ctx.Common_Authen_Role.Max(b => b.RoleID) + 1;
            var mdRole = this.ConvertDataModel(role);

            mdRole.ShowFlag = true;
            mdRole.RoleID   = maxId;
            ctx.Common_Authen_Role.Add(mdRole);
            ctx.SaveChanges();
            message = new MessageModel()
            {
                IsSuccess = true, MessageType = MessageType.InsertSuccess, Message = MessageResource.Message_CommonInsertSuccessful
            };

            Message = message;
        }
Ejemplo n.º 2
0
        public void UpdateRole(VM.RoleItemModel role)
        {
            MessageModel message = null;

            if (role == null)
            {
                message = new MessageModel()
                {
                    IsSuccess = false, Message = MessageResource.Role_Empty_ErrorMessage + "," + MessageResource.Message_CommonUpdateFail, MessageType = MessageType.UpdateFailure
                };
                return;
            }
            if (!ctx.Common_Authen_Role.Any(i => i.RoleID == role.Id))
            {
                message = new MessageModel()
                {
                    IsSuccess = false, MessageType = MessageType.UpdateFailure, Message = MessageResource.Role_Exits_ErrorMessage + "," + MessageResource.Message_CommonUpdateFail
                };
                return;
            }
            MD.Common_Authen_Role temp = ctx.Common_Authen_Role.First(i => i.RoleID == role.Id);
            temp.RoleName    = role.RoleName;
            temp.Description = role.Description;
            ctx.SaveChanges();
            message = new MessageModel()
            {
                IsSuccess = true, MessageType = MessageType.UpdateSuccess, Message = MessageResource.Message_CommonUpdateSuccessful
            };

            Message = message;
        }
Ejemplo n.º 3
0
 private MD.Common_Authen_Role ConvertDataModel(VM.RoleItemModel role)
 {
     if (role == null)
     {
         return(null);
     }
     return(new MD.Common_Authen_Role()
     {
         RoleID = role.Id,
         RoleName = role.RoleName,
         Description = role.Description
     });
 }