Beispiel #1
0
        private ChangeResult Validate(List <ITeam> teams, bool isAddNew = false)
        {
            ChangeResult result = new ChangeResult();

            UserService = new UserService();

            foreach (var item in teams)
            {
                if (!isAddNew)
                {
                    if (item.TeamId == Guid.Empty)
                    {
                        result.IsSuccess = false;
                        result.ErrorMessages.Add("Invalid TeamId");
                    }
                }

                if (item.TeamLeaderId.HasValue)
                {
                    if (item.TeamLeaderId == Guid.Empty)
                    {
                        result.IsSuccess = false;
                        result.ErrorMessages.Add("Invalid Team Leader Id");
                    }
                    else
                    {
                        var user = UserService.GetUser(item.TeamLeaderId.Value);
                        if (user == null)
                        {
                            result.IsSuccess = false;
                            result.ErrorMessages.Add($"Invalid Team Leader Id: {item.TeamLeaderId}");
                        }
                    }
                }

                if (string.IsNullOrWhiteSpace(item.TeamName))
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Team Name is required");
                }
                else if (item.TeamName.Trim().Length > 100)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Team Name cannot be longer than 100 characters");
                }

                if (!string.IsNullOrWhiteSpace(item.TeamDescription) && item.TeamDescription.Trim().Length > 500)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Team Description cannot be longer than 500 characters");
                }

                if (!string.IsNullOrWhiteSpace(item.TeamEmail) && !Helper.IsValidEmail(item.TeamEmail))
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add($"Invalid Team Email: {item.TeamEmail}");
                }
            }
            return(result);
        }
Beispiel #2
0
        public IActionResult _deleteTeam(string id)
        {
            ChangeResult result = new ChangeResult();
            Guid?        teamId = Helper.ConvertToGuid(id);

            if (teamId.HasValue)
            {
                var team = TeamService.GetTeam(teamId.Value);
                if (team != null)
                {
                    TeamDto dto = new TeamDto()
                    {
                        LocationId      = team.LocationId,
                        TeamDescription = team.TeamDescription,
                        TeamEmail       = team.TeamEmail,
                        TeamId          = team.TeamId,
                        TeamLeaderId    = team.TeamLeaderId,
                        TeamName        = team.TeamName,
                        DeleteDate      = DateTime.UtcNow
                    };
                    result = TeamService.UpdateTeam(dto);
                }
            }

            return(new JsonResult(result));
        }
Beispiel #3
0
        private ChangeResult Validate(List <IGameTeam> gameTeams, bool isAddNew = false)
        {
            ChangeResult result = new ChangeResult();

            foreach (var item in gameTeams)
            {
                if (!result.IsSuccess)
                {
                    break;
                }

                if (item.GameId == Guid.Empty)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Invalid Game.");
                }

                if (item.TeamId == Guid.Empty)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Invalid Team.");
                }
            }

            return(result);
        }
        public ChangeResult MarkScheduleDeleted(Guid scheduleId)
        {
            ChangeResult result = new ChangeResult();

            var update = GetSchedule(scheduleId);

            using (var context = new Data.ScheduleContext())
            {
                if (update != null && !update.DeleteDate.HasValue)
                {
                    context.Schedules.Update(new Domain.Schedule
                    {
                        ScheduleId       = update.ScheduleId.ToString(),
                        TeamId           = update.TeamId.ToString(),
                        UserId           = update.UserId.ToString(),
                        StartDate        = update.StartDate,
                        EndDate          = update.EndDate,
                        SupportLevel     = (int)update.SupportLevel,
                        LastUpdateDate   = DateTime.UtcNow,
                        LastUpdateUserId = update.LastUpdateUserId.ToString(),
                        DeleteDate       = DateTime.UtcNow
                    });

                    context.SaveChanges();
                }
            }
            return(result);
        }
Beispiel #5
0
        public IActionResult DeleteSchedule(Guid scheduleId, DateTime startDate, DateTime endDate)
        {
            ChangeResult result = new ChangeResult();

            var item = ScheduleService.GetSchedule(scheduleId);

            if (item != null)
            {
                ScheduleDto dto = new ScheduleDto
                {
                    ScheduleId   = item.ScheduleId,
                    StartDate    = startDate.ToUniversalTime(),
                    EndDate      = endDate.ToUniversalTime(),
                    TeamId       = item.TeamId,
                    CreateDate   = item.CreateDate,
                    CreateUserId = item.CreateUserId,
                    SupportLevel = item.SupportLevel,
                    UserId       = item.UserId,
                    DeleteDate   = DateTime.UtcNow
                };
                result = ScheduleService.SaveSchedule(dto);
            }

            return(Json(result));
        }
        public IActionResult _deleteUser(string id)
        {
            ChangeResult result = new ChangeResult();

            Guid?userId = Helper.ConvertToGuid(id);

            if (userId.HasValue)
            {
                var user = UserService.GetUser(userId.Value);
                if (user != null)
                {
                    UserDto dto = new UserDto()
                    {
                        BackupEmail        = user.BackupEmail,
                        BackupPhoneNumber  = user.BackupPhoneNumber,
                        FirstName          = user.FirstName,
                        LastName           = user.LastName,
                        MiddleInitial      = user.MiddleInitial,
                        PrimaryEmail       = user.PrimaryEmail,
                        PrimaryPhoneNumber = user.PrimaryPhoneNumber,
                        UserId             = user.UserId,
                        UserName           = user.UserName,
                        DeleteDate         = DateTime.UtcNow
                    };

                    result = UserService.UpdateUser(dto);
                }
            }

            return(new JsonResult(result));
        }
Beispiel #7
0
        public ChangeResult <string> DefineEmailConfirmation(string newValue)
        {
            if (newValue is null)
            {
                return(ChangeResult <string> .Failed(this, Properties.EmailConfirmation, "L'adresse email de confirmation doit être définie !", m_EmailConfirmation, newValue));
            }
            else if (!newValue.Equals(newValue.Trim()))
            {
                return(ChangeResult <string> .Failed(this, Properties.EmailConfirmation, "L'addresse email de confirmation ne peut pas commencer ou finir par un espace !", m_EmailConfirmation, newValue));
            }
            else if (!EmailHelper.IsValidEmail(newValue))
            {
                return(ChangeResult <string> .Failed(this, Properties.EmailConfirmation, "Le format de l'addresse email de confirmation n'est pas valide !", m_EmailConfirmation, newValue));
            }
            else if (newValue.Length > 100)
            {
                return(ChangeResult <string> .Failed(this, Properties.EmailConfirmation, "L'adresse email de confirmation doit faire au plus 100 caractères !", m_EmailConfirmation, newValue));
            }
            else if (!string.IsNullOrEmpty(Email) && !newValue.Equals(Email))
            {
                return(ChangeResult <string> .Failed(this, Properties.EmailConfirmation, "L'adresse email de confirmation doit être identique à l'adresse email !", m_EmailConfirmation, newValue));
            }

            newValue = newValue.ToLower();
            var initialValue = m_EmailConfirmation;

            m_EmailConfirmation = newValue;
            return(ChangeResult <string> .Succeded(this, Properties.EmailConfirmation, initialValue, newValue));
        }
Beispiel #8
0
        public ChangeResult <string> DefineEmail(string newValue)
        {
            if (newValue is null)
            {
                return(ChangeResult <string> .Failed(this, Properties.Email, "L'adresse email doit être définie !", m_Email, newValue));
            }
            else if (!newValue.Equals(newValue.Trim()))
            {
                return(ChangeResult <string> .Failed(this, Properties.Email, "L'addresse email ne peut pas commencer ou finir par un espace !", m_Email, newValue));
            }
            else if (!EmailHelper.IsValidEmail(newValue))
            {
                return(ChangeResult <string> .Failed(this, Properties.Email, "Le format de l'addresse email n'est pas valide !", m_Email, newValue));
            }
            else if (newValue.Length > 100)
            {
                return(ChangeResult <string> .Failed(this, Properties.Email, "L'adresse email doit faire au plus 100 caractères !", m_Email, newValue));
            }

            newValue = newValue.ToLower();
            var initialValue = m_Email;

            m_Email = newValue;
            return(ChangeResult <string> .Succeded(this, Properties.Email, initialValue, newValue));
        }
Beispiel #9
0
        private ChangeResult Validate(List <ILeague> leagues)
        {
            ChangeResult result = new ChangeResult();

            foreach (var league in leagues)
            {
                if (!result.IsSuccess)
                {
                    break;
                }

                if (string.IsNullOrWhiteSpace(league.Name))
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("League Name is required");
                }
                else if (league.Name.Length > 100)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("League Name must be less than 100 characters");
                }
            }

            return(result);
        }
Beispiel #10
0
        private ChangeResult Validate(List <IPlayerTeam> playerTeams, bool isAddNew = true)
        {
            ChangeResult result = new ChangeResult();

            foreach (var item in playerTeams)
            {
                if (!result.IsSuccess)
                {
                    break;
                }
                if (item.PlayerId == Guid.Empty)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Incorrect PlayerId.");
                }
                if (item.TeamId == Guid.Empty)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Incorrect TeamId.");
                }

                if (isAddNew == false)
                {
                    if (item.PlayerTeamId == Guid.Empty)
                    {
                        result.IsSuccess = false;
                        result.ErrorMessages.Add("Invalid Player Team Alternate Key.");
                    }
                }
            }

            return(result);
        }
Beispiel #11
0
        private ChangeResult Validate(List <IGame> games, bool isAddNew = false)
        {
            ChangeResult result = new ChangeResult();

            foreach (var item in games)
            {
                if (!result.IsSuccess)
                {
                    break;
                }

                if (item.LeagueId == Guid.Empty)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Invalid League.");
                }

                if (item.GameDate > DateTime.UtcNow)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Game cannot take place in the future.");
                }

                if (isAddNew == false)
                {
                    if (item.GameId == Guid.Empty)
                    {
                        result.IsSuccess = false;
                        result.ErrorMessages.Add("Invalid Game.");
                    }
                }
            }

            return(result);
        }
Beispiel #12
0
        public IActionResult EditScheduleModal(Models.Schedule.EditSchedule model)
        {
            ChangeResult result = new ChangeResult();

            if (ModelState.IsValid)
            {
                ScheduleDto dto = new ScheduleDto
                {
                    EndDate      = model.EndDate.ToUniversalTime(),
                    ScheduleId   = model.ScheduleId,
                    StartDate    = model.StartDate.ToUniversalTime(),
                    SupportLevel = model.SupportLevel,
                    TeamId       = model.TeamId,
                    UserId       = model.UserId
                };
                result = ScheduleService.SaveSchedule(dto);
            }
            else
            {
                model.FillTeamSelectList(TeamService.GetTeams());
                model.FillSupportLevelSelectList();
                model.UserSelectList = new List <SelectListItem>();
            }

            return(PartialView("_ScheduleEditPartial", model));
        }
Beispiel #13
0
        /// <summary>
        /// Attempts to change the user password.  Adds the password to user password history.
        /// Hashes password appropriately.
        /// </summary>
        /// <param name="password">New password.</param>
        /// <param name="token">Token from WebSecurity.GeneratePasswordResetToken</param>
        public ChangeResult ChangePassword(string password, string token, bool adminOverride = false)
        {
            // Can this password be used?
            ChangeResult changeResult = CheckPasswordHistory(password);

            if (changeResult == ChangeResult.Ok || adminOverride)
            {
                changeResult = WebSecurity.ResetPassword(token, password) ? ChangeResult.Ok : ChangeResult.TokenResetFailed;

                if (changeResult == ChangeResult.Ok)
                {
                    //dont update the pw history if the admin is doing it
                    if (!adminOverride)
                    {
                        AddPasswordToHistory(password);
                    }

                    //we also need to reset their password attempts here
                    var rbacEntities = new PEMRBACEntities();
                    var membership   = rbacEntities.Memberships.FirstOrDefault(x => x.UserId == _userId);
                    if (membership != null)
                    {
                        membership.PasswordFailuresSinceLastSuccess = 0;
                        rbacEntities.SaveChanges();
                    }
                }
            }

            SetLastError(changeResult);
            return(changeResult);
        }
Beispiel #14
0
        private ChangeResult Validate(List <ITeam> teams)
        {
            ChangeResult result = new ChangeResult();

            foreach (var team in teams)
            {
                if (!result.IsSuccess)
                {
                    break;
                }
                if (team.LeagueId == Guid.Empty)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Invalid League.");
                }
                else if (string.IsNullOrWhiteSpace(team.Name))
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Team Name is Required.");
                }
                else if (team.Name.Trim().Length > 100)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Team Name cannot be longer than 100 characters.");
                }
            }

            return(result);
        }
        public IActionResult _deleteCategory(string id)
        {
            Guid?        categoryId = Helper.ConvertToGuid(id);
            ChangeResult result     = new ChangeResult();

            if (categoryId.HasValue)
            {
                var model = CategoryService.GetCategory(categoryId.Value);
                if (model != null)
                {
                    CategoryDto dto = new CategoryDto()
                    {
                        CategoryDescription = model.CategoryDescription,
                        CategoryEmail       = model.CategoryEmail,
                        CategoryId          = model.CategoryId,
                        CategoryName        = model.CategoryName,
                        DeleteDate          = model.DeleteDate
                    };

                    result = CategoryService.UpdateCategory(dto);
                }
            }

            return(new JsonResult(result));
        }
Beispiel #16
0
        private ChangeResult Validate(List <ITeamPlayerLineup> teamPlayerLineups, bool isAddNew = true)
        {
            ChangeResult result = new ChangeResult();

            foreach (var item in teamPlayerLineups)
            {
                if (!result.IsSuccess)
                {
                    break;
                }

                if (item.TeamId == Guid.Empty)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Invalid Team.");
                }
                else if (item.PlayerId == Guid.Empty)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Invalid Player.");
                }

                if (isAddNew == false)
                {
                }
            }

            return(result);
        }
Beispiel #17
0
        public void TakeSnapshot_should_return_snapshot_of_single_key()
        {
            // arrange
            RegistrySnapshotBuilder target;
            RegistryKeySnapshot     snapshot;
            RegistryKeySnapshot     compare;
            RegistrySnapshot        lhs;
            RegistrySnapshot        rhs;

            ChangeResult[] expected;
            ChangeResult[] actual;

            target       = new RegistrySnapshotBuilder();
            compare      = this.LoadBaseSnapshot().Keys[0];
            compare.Name = "Tests";
            lhs          = new RegistrySnapshot();
            lhs.Keys.Add(compare);

            expected = new ChangeResult[0];

            this.CreateBase();

            // act
            snapshot = target.TakeSnapshot(this.FullRootKeyName);

            // assert
            rhs = new RegistrySnapshot();
            rhs.Keys.Add(snapshot);
            actual = new RegistrySnapshotComparer(lhs, rhs).Compare();
            CollectionAssert.AreEqual(expected, actual);
        }
Beispiel #18
0
        private void CompareSnapshots()
        {
            RegistrySnapshot lhs;
            RegistrySnapshot rhs;

            ChangeResult[] results;

            lhs     = null;
            rhs     = null;
            results = new ChangeResult[0];

            this.PerformAction(() => lhs = RegistrySnapshot.LoadFromFile(PathHelpers.GetFullPath(_files[0])),
                               "Loading first snapshot");
            this.PerformAction(() => rhs = RegistrySnapshot.LoadFromFile(PathHelpers.GetFullPath(_files[1])),
                               "Loading second snapshot");

            if (lhs != null && rhs != null)
            {
                this.PerformAction(() =>
                {
                    RegistrySnapshotComparer comparer;

                    comparer = new RegistrySnapshotComparer(lhs, rhs);

                    results = comparer.Compare();
                }, "Comparing snapshots");
            }

            this.PrintResults(results);

            if (this.ExitCode == ExitCode.InvalidArguments)
            {
                this.ExitCode = results.Length == 0 ? ExitCode.Success : ExitCode.CompareMismatch;
            }
        }
Beispiel #19
0
        public void UpdateBlock(Player p, ushort x, ushort y, ushort z, BlockID block,
                                ushort flags = BlockDBFlags.ManualPlace, bool buffered = false)
        {
            int     index;
            BlockID old   = GetBlock(x, y, z, out index);
            bool    drawn = (flags & BlockDBFlags.ManualPlace) == 0;

            ChangeResult result = TryChangeBlock(p, x, y, z, block, drawn);

            if (result == ChangeResult.Unchanged)
            {
                return;
            }

            BlockDB.Cache.Add(p, x, y, z, flags, old, block);
            if (result == ChangeResult.VisuallySame)
            {
                return;
            }

            if (buffered)
            {
                p.level.blockqueue.Add(index, block);
            }
            else
            {
                BroadcastChange(x, y, z, block);
            }
        }
Beispiel #20
0
        public IActionResult _deleteLocation(string id)
        {
            ChangeResult result     = new ChangeResult();
            Guid?        locationId = Helper.ConvertToGuid(id);

            if (locationId.HasValue)
            {
                var model = LocationService.GetLocation(locationId.Value);
                if (model != null)
                {
                    LocationDto dto = new LocationDto()
                    {
                        Address      = model.Address,
                        City         = model.City,
                        Country      = model.Country,
                        Description  = model.Description,
                        LocationId   = model.LocationId,
                        LocationName = model.LocationName,
                        StateRegion  = model.StateRegion,
                        ZipCode      = model.ZipCode,
                        DeleteDate   = DateTime.UtcNow
                    };

                    result = LocationService.UpdateLocation(dto);
                }
            }

            return(new JsonResult(result));
        }
Beispiel #21
0
        private ChangeResult Validate(List <IGameInning> gameInnings, bool isAddNew = false)
        {
            ChangeResult result = new ChangeResult();

            foreach (var item in gameInnings)
            {
                if (!result.IsSuccess)
                {
                    break;
                }

                if (item.GameId == Guid.Empty)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Invalid Game.");
                }

                if (item.InningNumber < 1)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add($"Invalid Inning: {item.InningNumber}.");
                }

                if (!isAddNew)
                {
                    if (item.GameInningId == Guid.Empty)
                    {
                        result.IsSuccess = false;
                        result.ErrorMessages.Add("Invalid Game Inning Id.");
                    }
                }
            }
            return(result);
        }
Beispiel #22
0
        private void SetLastError(ChangeResult changeResult)
        {
            switch (changeResult)
            {
            case ChangeResult.AlreadyUsed:
                LastError = "Password has already been used.";
                break;

            case ChangeResult.GeneralError:
                LastError = "General error checking password.";
                break;

            case ChangeResult.MatchesUserName:
                LastError = "Password same as user name.";
                break;

            case ChangeResult.OnlyOneChangePerDay:
                LastError = "Password may only be changed once in a 24-hour period.";
                break;

            case ChangeResult.TokenResetFailed:
                LastError = "Password could not be changed. If the problem persists please contact your system administrator";
                break;

            default:
                LastError = "";
                break;
            }
        }
        public void SaveTeams(object sender, EventArgs args)
        {
            ChangeResult result = new ChangeResult();

            Models.Team awayTeam = null;
            Models.Team homeTeam = null;

            if (AwayTeamPicker.SelectedIndex >= 0)
            {
                awayTeam = ViewModel.AwayTeams[AwayTeamPicker.SelectedIndex];
            }
            if (HomeTeamPicker.SelectedIndex >= 0)
            {
                homeTeam = ViewModel.HomeTeams[HomeTeamPicker.SelectedIndex];
            }

            if (awayTeam == null)
            {
                result.IsSuccess = false;
                result.ErrorMessages.Add("Please select an away team.");
            }
            if (homeTeam == null)
            {
                result.IsSuccess = false;
                result.ErrorMessages.Add("Please select a home team.");
            }

            if (result.IsSuccess && awayTeam.TeamId == homeTeam.TeamId)
            {
                result.IsSuccess = false;
                result.ErrorMessages.Add("Please select two different teams.");
            }

            if (result.IsSuccess)
            {
                result = ViewModel.SaveGameTeams(awayTeam, homeTeam);
            }

            if (!result.IsSuccess)
            {
                StringBuilder sb    = new StringBuilder();
                int           index = 0;

                foreach (var item in result.ErrorMessages)
                {
                    if (index > 0)
                    {
                        sb.Append(" ");
                    }
                    sb.Append(item);
                    index++;
                }
                DisplayAlert("Alert", sb.ToString(), "OK");
            }
            else
            {
                Navigation.PushAsync(new SetupGameReviewPage(ViewModel.GameId));
            }
        }
Beispiel #24
0
 /// <summary>
 /// Set the last move to current tick count in order to be used for lock delay mechanism
 /// </summary>
 /// <param name="changeResult"></param>
 private void SetLastMove(ChangeResult changeResult)
 {
     if (changeResult != null)
     {
         lastMove          = changeResult.LastMove;
         lastMoveTickCount = Environment.TickCount;
     }
 }
Beispiel #25
0
        /// <summary>
        /// Sets the last move value in the result
        /// </summary>
        /// <param name="moveResult"></param>
        private void SetLastMove(ChangeResult moveResult)
        {
            if (moveResult == null)
            {
                return;
            }

            moveResult.LastMove = !current.CanMoveDown();
        }
Beispiel #26
0
 public static void Call(Player p, ushort x, ushort y, ushort z, ChangeResult result)
 {
     IEvent <OnBlockChanged>[] items = handlers.Items;
     for (int i = 0; i < items.Length; i++)
     {
         try { items[i].method(p, x, y, z, result); }
         catch (Exception ex) { LogHandlerException(ex, items[i]); }
     }
 }
Beispiel #27
0
        public ChangeResult SaveTeamCategories(Guid teamId, List <Guid> categoryIds, Guid?changeUserId = null)
        {
            ChangeResult result = new ChangeResult();

            using (var context = new Data.ScheduleContext())
            {
                var         existingTeamCats = context.TeamCategories.Where(x => x.TeamId == teamId.ToString());
                List <Guid> existingCatIds   = new List <Guid>();

                foreach (var item in existingTeamCats)
                {
                    if (!categoryIds.Contains(Guid.Parse(item.CategoryId)) && !item.DeleteDate.HasValue)
                    {
                        item.DeleteDate     = DateTime.UtcNow;
                        item.LastUpdateDate = DateTime.UtcNow;
                        if (changeUserId.HasValue)
                        {
                            item.LastUpdateUserId = changeUserId.Value.ToString();
                        }
                    }
                    else if (item.DeleteDate.HasValue)
                    {
                        item.DeleteDate     = null;
                        item.LastUpdateDate = DateTime.UtcNow;
                        if (changeUserId.HasValue)
                        {
                            item.LastUpdateUserId = changeUserId.Value.ToString();
                        }
                    }
                    existingCatIds.Add(Guid.Parse(item.CategoryId));
                }

                foreach (Guid categoryId in categoryIds)
                {
                    if (!existingCatIds.Contains(categoryId))
                    {
                        context.TeamCategories.Add(new Domain.TeamCategory()
                        {
                            TeamCategoryId   = Guid.NewGuid().ToString(),
                            CategoryId       = categoryId.ToString(),
                            TeamId           = teamId.ToString(),
                            CreateDate       = DateTime.UtcNow,
                            LastUpdateDate   = DateTime.UtcNow,
                            CreateUserId     = changeUserId.HasValue ? changeUserId.Value.ToString() : null,
                            LastUpdateUserId = changeUserId.HasValue ? changeUserId.Value.ToString() : null
                        });
                    }
                }

                context.SaveChanges();
            }

            return(result);
        }
Beispiel #28
0
        public ChangeResult SaveTeamUsers(Guid teamId, List <Guid> userIds, Guid?changeUserId = null)
        {
            ChangeResult result = new ChangeResult();

            using (var context = new Data.ScheduleContext())
            {
                var         existingUsers   = context.TeamUsers.Where(x => x.TeamId == teamId.ToString()).ToList();
                List <Guid> existingUserIds = new List <Guid>();
                foreach (var user in existingUsers)
                {
                    if (!userIds.Contains(Guid.Parse(user.UserId)))
                    {
                        user.DeleteDate     = DateTime.UtcNow;
                        user.LastUpdateDate = DateTime.UtcNow;
                        if (changeUserId.HasValue)
                        {
                            user.LastUpdateUserId = changeUserId.Value.ToString();
                        }
                    }
                    else if (user.DeleteDate.HasValue)
                    {
                        user.DeleteDate     = null;
                        user.LastUpdateDate = DateTime.UtcNow;
                        if (changeUserId.HasValue)
                        {
                            user.LastUpdateUserId = changeUserId.Value.ToString();
                        }
                    }
                    existingUserIds.Add(Guid.Parse(user.UserId));
                }

                foreach (Guid userId in userIds)
                {
                    if (!existingUserIds.Contains(userId))
                    {
                        context.TeamUsers.Add(new Domain.TeamUser()
                        {
                            TeamUserId       = Guid.NewGuid().ToString(),
                            TeamId           = teamId.ToString(),
                            UserId           = userId.ToString(),
                            CreateDate       = DateTime.UtcNow,
                            CreateUserId     = changeUserId.HasValue ? changeUserId.Value.ToString() : null,
                            LastUpdateDate   = DateTime.UtcNow,
                            LastUpdateUserId = changeUserId.HasValue ? changeUserId.Value.ToString() : null,
                            DeleteDate       = null
                        });
                    }
                }

                context.SaveChanges();
            }

            return(result);
        }
Beispiel #29
0
        private ChangeResult Validate(List <ITeamUser> teamUsers, bool isAddNew = false)
        {
            ChangeResult result = new ChangeResult();

            Team = new TeamService();
            User = new UserService();

            foreach (var item in teamUsers)
            {
                var existingCombo = GetTeamUser(item.TeamId, item.UserId);
                if (isAddNew)
                {
                    if (existingCombo != null)
                    {
                        var display = GetTeamNameUserDisplayName(item.TeamId, item.UserId);

                        result.IsSuccess = false;
                        result.ErrorMessages.Add($"{display.Item2} is already a member of team {display.Item1}");
                    }
                }
                else
                {
                    if (item.TeamUserId == Guid.Empty)
                    {
                        result.IsSuccess = false;
                        result.ErrorMessages.Add("Invalid TeamUserId");
                    }

                    if (existingCombo != null && existingCombo.TeamUserId != item.TeamUserId)
                    {
                        var display = GetTeamNameUserDisplayName(item.TeamId, item.UserId);

                        result.IsSuccess = false;
                        result.ErrorMessages.Add($"{display.Item2} is already a member of team {display.Item1}");
                    }
                }

                var user = User.GetUser(item.UserId);
                if (user == null)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Invalid UserId");
                }

                var team = Team.GetTeam(item.TeamId);
                if (team == null)
                {
                    result.IsSuccess = false;
                    result.ErrorMessages.Add("Invalid TeamId");
                }
            }

            return(result);
        }
Beispiel #30
0
        public ChangeResult <string> DefineOldPassword(string newValue)
        {
            if (newValue is null)
            {
                return(ChangeResult <string> .Failed(this, Properties.OldPassword, "L'ancien mot de passe est requis !", m_OldPassword, newValue));
            }
            var initialValue = m_OldPassword;

            m_OldPassword = newValue;
            return(ChangeResult <string> .Succeded(this, Properties.OldPassword, initialValue, newValue));
        }
Beispiel #31
0
    private void CompareSnapshots()
    {
      RegistrySnapshot lhs;
      RegistrySnapshot rhs;
      ChangeResult[] results;

      lhs = null;
      rhs = null;
      results = new ChangeResult[0];

      this.PerformAction(() => lhs = RegistrySnapshot.LoadFromFile(PathHelpers.GetFullPath(_files[0])),
                         "Loading first snapshot");
      this.PerformAction(() => rhs = RegistrySnapshot.LoadFromFile(PathHelpers.GetFullPath(_files[1])),
                         "Loading second snapshot");

      if (lhs != null && rhs != null)
      {
        this.PerformAction(() =>
                           {
                             RegistrySnapshotComparer comparer;

                             comparer = new RegistrySnapshotComparer(lhs, rhs);

                             results = comparer.Compare();
                           }, "Comparing snapshots");
      }

      this.PrintResults(results);

      if (this.ExitCode == ExitCode.InvalidArguments)
      {
        this.ExitCode = results.Length == 0 ? ExitCode.Success : ExitCode.CompareMismatch;
      }
    }
 public ViewCompareResultsDialog(ChangeResult[] results)
     : this()
 {
     _results = results.ToList();
 }
        public void Compare_should_return_no_results_when_snapshots_are_equal()
        {
            // arrange
              RegistrySnapshotComparer target;
              ChangeResult[] expected;
              ChangeResult[] actual;
              RegistrySnapshot lhs;
              RegistrySnapshot rhs;

              expected = new ChangeResult[0];

              rhs = this.LoadBaseSnapshot();
              lhs = this.LoadBaseSnapshot();

              target = new RegistrySnapshotComparer(lhs, rhs);

              // act
              actual = target.Compare();

              // assert
              CollectionAssert.AreEqual(expected, actual);
        }
Beispiel #34
0
    private void PrintResults(ChangeResult[] results)
    {
      if (results.Length == 0)
      {
        Console.WriteLine("\nNo changes detected.");
      }
      else
      {
        Console.WriteLine();

        foreach (ChangeResult result in results)
        {
          switch (result.Type)
          {
            case ChangeType.Insertion:
              Console.ForegroundColor = ConsoleColor.Green;
              Console.Write("NEW");
              break;
            case ChangeType.Deletion:
              Console.ForegroundColor = ConsoleColor.Red;
              Console.Write("DEL");
              break;
            case ChangeType.Modification:
              Console.ForegroundColor = ConsoleColor.Green;
              Console.Write("UPD");
              break;
            default:
              throw new ArgumentOutOfRangeException();
          }

          Console.ForegroundColor = ConsoleColor.Gray;
          Console.Write('\t');
          Console.Write(result.KeyName);

          if (result.ValueName != null)
          {
            Console.Write('@');
            Console.Write(result.ValueName);
          }

          Console.WriteLine();
        }
      }
    }
Beispiel #35
0
 private void HandleCompareResults(ChangeResult[] results)
 {
     if (results.Length == 0)
       {
     MessageBox.Show("No differences found.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
       }
       else
       {
     using (ViewCompareResultsDialog dialog = new ViewCompareResultsDialog(results))
     {
       dialog.ShowDialog(this);
     }
       }
 }