Exemple #1
0
        public List <SaveResult <UserDTO> > GetSaveResults(List <UserDTO> userList, DateTime dateStamp)
        {
            var validationResults = Validate(userList);
            List <SaveResult <UserDTO> > saveResults = new List <SaveResult <UserDTO> >();

            foreach (var validationResult in validationResults)
            {
                var userDTO       = (UserDTO)validationResult.GetModel();
                var createHandler = new UserCreateHandler(Db, User, new UserValidator(), new UserFactory(Db, User), new UserQuery(Db), new AccessControl(this.User));
                var updateHandler = new UserUpdateHandler(Db, User, new UserValidator(), new UserFactory(Db, User), new UserQuery(Db), new AccessControl(User));
                if (validationResult.IsValid)
                {
                    if (userDTO.User_PK > 0)
                    {
                        updateHandler.Save(userDTO, dateStamp);
                        //DeleteMappingUserRoleGroup(userDTO);
                        //UpdateUser(userDTO, dateStamp);
                        //CreateRoleGroupIfJabatanIsAssignable(userDTO, dateStamp);
                    }
                    else
                    {
                        createHandler.Save(userDTO, dateStamp);
                        //AddUser(userDTO, dateStamp);
                        //CreateRoleGroupIfJabatanIsAssignable(userDTO, dateStamp);
                    }

                    var saveResult = new SaveResult <UserDTO>()
                    {
                        Message          = "SUCCESS",
                        Model            = userDTO,
                        Success          = true,
                        ValidationResult = validationResult,
                    };
                    saveResults.Add(saveResult);
                }
                else
                {
                    var saveResult = new SaveResult <UserDTO>()
                    {
                        Message          = "FAILED",
                        Model            = userDTO,
                        Success          = false,
                        ValidationResult = validationResult,
                    };
                    saveResults.Add(saveResult);
                }
            }
            return(saveResults);
        }
Exemple #2
0
        public List <SaveResult <UserDTO> > Import(UserImportDTO userImportDTO)
        {
            using (var userCreateHandler = new UserCreateHandler(db, user, new UserValidator(), new UserFactory(db, user), new UserQuery(db), new AccessControl(user)))
            {
                using (var transaction = new TransactionScope())
                {
                    List <SaveResult <UserDTO> > saveResults = new List <SaveResult <UserDTO> >();

                    var stream = new CSVConverter().GetStreamFromBase64(userImportDTO.File);
                    using (var reader = new StreamReader(stream))
                    {
                        int current      = 0;
                        var jabatanQuery = new KategoriJabatan.Queries.KategoriJabatanQuery(db);
                        while (!reader.EndOfStream)
                        {
                            var line = reader.ReadLine();
                            if (current == 0)
                            {
                                current++;
                                continue;
                            }
                            var     values  = line.Split(';');
                            UserDTO userDTO = CreateUserDTO(jabatanQuery, values);

                            var saveResult = userCreateHandler.Save(userDTO: userDTO, dateStamp: DateTime.UtcNow);
                            saveResults.Add(new SaveResult <UserDTO>()
                            {
                                Message          = saveResult.Message,
                                Model            = saveResult.Model?.Model,
                                Success          = saveResult.Success,
                                ValidationResult = saveResult.ValidationResult
                            });
                            current++;
                        }
                    }
                    transaction.Complete();

                    return(saveResults);
                }
            }
        }