예제 #1
0
        public tblM_MappingUserToRoleGroup Insert(MappingUserToRoleGroupDTO mappingUserToRoleGroupDTO, DateTime dateStamp)
        {
            if (mappingUserToRoleGroupDTO == null)
            {
                throw new ArgumentNullException("MappingUserToRoleGroup model is null.");
            }

            var recordIsExist = Db.tblM_MappingUserToRoleGroup.Find(mappingUserToRoleGroupDTO.User_PK, mappingUserToRoleGroupDTO.RoleGroup_PK) != null;

            if (recordIsExist)
            {
                throw new KairosException("User already exist in the group.");
            }

            var user = new UserQuery(Db).GetByPrimaryKey((int)mappingUserToRoleGroupDTO.User_PK);

            if (user != null)
            {
                if (assignableJabatan.Contains(user.KategoriJabatan_FK))
                {
                    var mappingUserRoleGroupCount = Db.tblM_MappingUserToRoleGroup.Where(x => x.User_PK == user.User_PK).Count();
                    //if (mappingUserRoleGroupCount > 0)
                    //{
                    //    throw new KairosException($"This user cannot have more than one role group because its position is '{user.KategoriJabatanTitle}'.");
                    //}
                }
            }

            tblM_MappingUserToRoleGroup mappingUserToRoleGroup = mappingUserToRoleGroupFactory.CreateFromDTO(mappingUserToRoleGroupDTO, dateStamp);

            return(Db.tblM_MappingUserToRoleGroup.Add(mappingUserToRoleGroup));
        }
        public tblM_MappingUserToRoleGroup Insert(MappingUserToRoleGroupDTO mappingUserToRoleGroupDTO, DateTime dateStamp)
        {
            if (mappingUserToRoleGroupDTO == null)
            {
                throw new ArgumentNullException("MappingUserToRoleGroup model is null.");
            }

            var recordIsExist = Db.tblM_MappingUserToRoleGroup.Find(mappingUserToRoleGroupDTO.User_PK, mappingUserToRoleGroupDTO.RoleGroup_PK) != null;

            if (recordIsExist)
            {
                throw new KairosException("User already exist in the group.");
            }

            tblM_MappingUserToRoleGroup mappingUserToRoleGroup = mappingUserToRoleGroupFactory.CreateFromDTO(mappingUserToRoleGroupDTO, dateStamp);

            return(Db.tblM_MappingUserToRoleGroup.Add(mappingUserToRoleGroup));
        }