private void SoftDelete(tblM_MappingUserToRoleGroup mappingUserToRoleGroup)
 {
     if (mappingUserToRoleGroup != null)
     {
         mappingUserToRoleGroup.Status_FK = (int)RecordStatus.Deleted;
     }
 }
 private void HardDelete(tblM_MappingUserToRoleGroup mappingUserToRoleGroup)
 {
     if (mappingUserToRoleGroup != null)
     {
         Db.tblM_MappingUserToRoleGroup.Remove(mappingUserToRoleGroup);
     }
 }
Пример #3
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 void Update(MappingUserToRoleGroupDTO mappingUserToRoleGroupDTO, DateTime dateStamp)
 {
     if (mappingUserToRoleGroupDTO == null)
     {
         throw new ArgumentNullException("MappingUserToRoleGroup model is null.");
     }
     tblM_MappingUserToRoleGroup mappingUserToRoleGroup = mappingUserToRoleGroupFactory.CreateFromDbAndUpdateFromDTO(mappingUserToRoleGroupDTO, dateStamp);
 }
        public tblM_MappingUserToRoleGroup CreateFromDTO(MappingUserToRoleGroupDTO mappingUserToRoleGroupDTO, DateTime dateStamp)
        {
            if (mappingUserToRoleGroupDTO == null)
            {
                throw new ArgumentNullException("MappingUserToRoleGroup model is null.");
            }
            mappingUserToRoleGroupDTO.Status_FK   = (int)RecordStatus.Active;
            mappingUserToRoleGroupDTO.CreatedBy   = User.Username;
            mappingUserToRoleGroupDTO.CreatedDate = dateStamp;
            mappingUserToRoleGroupDTO.UpdatedBy   = User.Username;
            mappingUserToRoleGroupDTO.UpdatedDate = dateStamp;
            tblM_MappingUserToRoleGroup mappingUserToRoleGroup = mappingUserToRoleGroupDTO.ToObject <tblM_MappingUserToRoleGroup>();

            return(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));
        }
        public SaveResult <MappingUserToRoleGroupEntryModel> Save(MappingUserToRoleGroupDTO mappingUserToRoleGroupDTO, DateTime dateStamp)
        {
            ModelValidationResult validationResult = mappingUserToRoleGroupValidator.Validate(mappingUserToRoleGroupDTO);
            bool success = false;
            MappingUserToRoleGroupEntryModel model = null;

            if (validationResult.IsValid)
            {
                tblM_MappingUserToRoleGroup mappingUserToRoleGroup = Insert(mappingUserToRoleGroupDTO, dateStamp);
                Db.SaveChanges();

                success = true;
                model   = mappingUserToRoleGroupEntryDataProvider.Get(mappingUserToRoleGroup.RoleGroup_PK, mappingUserToRoleGroup.User_PK);
            }

            return(new SaveResult <MappingUserToRoleGroupEntryModel>
            {
                Success = success,
                Message = validationResult.IsValid ? "Data successfully created." : "Validation error occured.",
                Model = model,
                ValidationResult = validationResult
            });
        }
        public DeleteResult <tblM_MappingUserToRoleGroup> Execute(int roleGroupPk, int userPk, DeleteMethod deleteMethod)
        {
            tblM_MappingUserToRoleGroup mappingUserToRoleGroup = Db.tblM_MappingUserToRoleGroup.Find(userPk, roleGroupPk);

            if (mappingUserToRoleGroup == null)
            {
                return(new DeleteResult <tblM_MappingUserToRoleGroup>()
                {
                    Success = false,
                    Message = $"Id '{roleGroupPk} and {userPk}' is not found.",
                    Record = null
                });
            }

            switch (deleteMethod)
            {
            case DeleteMethod.Soft:
                SoftDelete(mappingUserToRoleGroup);
                break;

            case DeleteMethod.Hard:
                HardDelete(mappingUserToRoleGroup);
                break;

            default:
                break;
            }

            Db.SaveChanges();

            return(new DeleteResult <tblM_MappingUserToRoleGroup>()
            {
                Success = true,
                Message = $"User member of role group successfully deleted.",
                Record = mappingUserToRoleGroup
            });
        }