예제 #1
0
        public IActionResult AssociatePlayer(AssociationViewModel association)
        {
            Club newClub = clubRepository.GetById(association.ClubId);

            playerRepository.AddToClub(association.Player, newClub);
            return(View("ManagePlayers", playerRepository.Players));
        }
예제 #2
0
        public IActionResult AssociatePlayer(int playerId)
        {
            Player             player = playerRepository.GetById(playerId);
            IEnumerable <Club> clubs  = clubRepository.Clubs;

            AssociationViewModel associationViewModel = new AssociationViewModel(clubs, player);

            return(View(associationViewModel));
        }
예제 #3
0
        public ActionResult Create([Bind(Include = "ID,StarDateTime,EndDateTime,AdId,NewspaperId")] AssociationViewModel associationviewmodel)
        {
            if (ModelState.IsValid)
            {
                _service.AddAssociation(associationviewmodel.StarDateTime, associationviewmodel.EndDateTime, associationviewmodel.AdId, associationviewmodel.NewspaperId);
                return(RedirectToAction("Index"));
            }

            return(View(associationviewmodel));
        }
예제 #4
0
 public ActionResult Edit([Bind(Include = "ID,StarDateTime,EndDateTime,AdId,NewspaperId")] AssociationViewModel associationviewmodel)
 {
     if (ModelState.IsValid)
     {
         Association association = Mapper.Map <AssociationViewModel, Association>(associationviewmodel);
         _service.SaveAssociation(association);
         return(RedirectToAction("Index"));
     }
     return(View(associationviewmodel));
 }
        public void Add(AssociationViewModel viewModel)
        {
            _repository.Add(new Association
            {
                CreationDate = DateTime.Now,
                IsItDeleted  = false,
                Status       = true,

                Name   = viewModel.Name,
                Image  = "/Areas/Login/Assets/images/" + viewModel.Image,
                Adress = viewModel.Adress,
                Count  = (viewModel.Count) + 1
            });
        }
예제 #6
0
        // GET: /Association/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AssociationViewModel associationviewmodel = Mapper.Map <Association, AssociationViewModel>(_service.FindAssociation(id));

            if (associationviewmodel == null)
            {
                return(HttpNotFound());
            }
            return(View(associationviewmodel));
        }
        public void Update(AssociationViewModel viewModel)
        {
            var associations = _repository.Get(x => x.Id == viewModel.Id);

            associations.Status       = viewModel.Status;
            associations.DateOfUpdate = DateTime.Now;
            associations.IsItDeleted  = viewModel.IsItDeleted;

            associations.Name   = viewModel.Name;
            associations.Adress = viewModel.Adress;
            associations.Count  = viewModel.Count;
            associations.Image  = viewModel.Image;

            _repository.Update(associations);
        }
예제 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SonarQubeUserControlVs"/> class.
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        public AssociationView(AssociationViewModel model)
        {
            if (model != null)
            {
                model.RequestClose += (s, e) => this.Close();
            }

            this.DataContext = model;
            try
            {
                this.InitializeComponent();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
예제 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AssociationModel" /> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="service">The service.</param>
        /// <param name="configurationHelper">The configuration helper.</param>
        /// <param name="translator">The translator.</param>
        /// <param name="pluginManager">The plugin manager.</param>
        /// <param name="model">The model.</param>
        public AssociationModel(
            INotificationManager logger,
            ISonarRestService service,
            IConfigurationHelper configurationHelper,
            ISQKeyTranslator translator,
            IPluginManager pluginManager,
            SonarQubeViewModel model)
        {
            this.keyTranslator       = translator;
            this.pluginManager       = pluginManager;
            this.model               = model;
            this.configurationHelper = configurationHelper;
            this.logger              = logger;
            this.sonarService        = service;

            // start view model
            this.associationViewModel = new AssociationViewModel(this);
        }
예제 #10
0
        public void An_error_is_received_if_a_user_tries_to_associate_his_corp_id_with_an_unknown_SIMPL_username()
        {
            using (ShimsContext.Create())
            {
                //Setup
                var calledSetCurrentUser = false;
                ShimCurrentUser.SetInstanceString = delegate { calledSetCurrentUser = true; };

                var calledSetAuthCookie = false;
                ShimFormsAuthentication.SetAuthCookieStringBooleanString = delegate { calledSetAuthCookie = true; };
                ShimErrorLoggingService.AllInstances.LogErrorException = (method, myException) =>
                {
                    // Not returning anything, just redirecting the call
                };
                // Given a user
                const string corpUserName = "******";
                const string corpPassword = "******";
                const string simplUserName = "******";
                const string simplPassword = "******";
                var requestStub = new StubHttpRequestBase();
                var contextStub = new StubHttpContextBase {RequestGet = () => requestStub};
                var userAssociationModel = new AssociationViewModel();

                // And has known corp credentials
                userAssociationModel.UserName = corpUserName;
                userAssociationModel.Password = corpPassword;

                // And has unknown SIMPL credentials
                userAssociationModel.SIMPLUserName = simplUserName;
                userAssociationModel.SIMPLPassword = simplPassword;

                var wasAttemptToLogUserInCalledForCorp = false;
                var wasAttemptToLogUserInCalledForSIMPL = false;
                ShimLoginModel.AllInstances.AttemptToLogUserInStringString = (loginModel, userName, password) =>
                {
                    if (userName == corpUserName && password == corpPassword)
                    {
                        wasAttemptToLogUserInCalledForCorp = true;
                        return new LoginModel()
                        {
                            Message = SIMPL.Models.Code.Constants.Areas.Common.LoginModel.AuthenticationResultMessages.NoUserRoles
                        };
                    }
                    if (userName == simplUserName && password == simplPassword)
                    {
                        wasAttemptToLogUserInCalledForSIMPL = true;
                        return new LoginModel()
                        {
                            Errors = true,
                            Message = SIMPL.Models.Code.Constants.Areas.Common.LoginModel.AuthenticationResultMessages.BadOrIncorrectUsernameOrPassword
                        };
                    }
                    return new LoginModel()
                    {
                        Errors = true,
                        Message = SIMPL.Models.Code.Constants.Areas.Common.LoginModel.AuthenticationResultMessages.UnknownResult
                    };
                };

                // And corp username doesn’t match SIMPL username
                // When submitting association form
                LoginControllerForTests.ControllerContext = new ControllerContext {HttpContext = contextStub};
                var userAssociationResult = LoginControllerForTests.UserNameAssociation(userAssociationModel);

                // Then association fails
                Assert.IsNotNull(userAssociationResult);
                #pragma warning disable 183
                // ReSharper generates a warning on the next line, but having this check will guarantee that the return type is checked before the other asserts
                Assert.IsTrue(userAssociationResult is ActionResult,
                    "The return from the UserLogin action method was not a ActionResult");
                #pragma warning restore 183
                Assert.IsTrue(userAssociationResult is ViewResult,
                    "The return from the UserLogin action method was not a ViewResult");

                // And user is not logged in
                Assert.IsFalse(calledSetCurrentUser, "The set CurrentUser was called");
                Assert.IsFalse(calledSetAuthCookie, "The set Authorization cookie was called");

                //And a message is displayed stating “Username association failed, please check your SIMPL credentials and try again”
                Assert.IsTrue(wasAttemptToLogUserInCalledForCorp, "Corp credentials were not Authorized");
                Assert.IsTrue(wasAttemptToLogUserInCalledForSIMPL, "SIMPL credentials were not Authorized");

                var result = userAssociationResult as ViewResult;
                var resultModel = result.Model as AssociationViewModel;
                Assert.IsNotNull(resultModel, "The model was null");
                Assert.IsNotNull(resultModel.Message, "The error message was missing.");
                const string expectedMessage =
                    "SIMPL login credentials are incorrect, please check your credentials and try again.";
                Assert.AreEqual(expectedMessage, resultModel.Message,
                    string.Format("The error message was {0}, it should have been {1}", resultModel.Message,
                        expectedMessage));
            }
        }
예제 #11
0
        public void A_user_can_associate_SIMPL_username_to_their_corp_username()
        {
            using (ShimsContext.Create())
            {
                //Setup

                var session = new System.Web.SessionState.Fakes.ShimHttpSessionState()
                {
                    ItemGetString = (key) =>
                    {
                        return key == "CurrentUser" ? new ShimCurrentUser() : null;
                    }
                };
                var context = new System.Web.Fakes.ShimHttpContext();
                var applicationShim = new System.Web.Fakes.ShimHttpApplicationState();
                context.ApplicationGet = delegate { return applicationShim; };

                System.Web.Fakes.ShimHttpContext.CurrentGet = delegate { return context; };
                System.Web.Fakes.ShimHttpContext.AllInstances.SessionGet = delegate { return session; };

                ShimUserEvents.AllInstances.InitializeSessionStringString = delegate { };
                ShimSingleConcurrentLoginManager.AllInstances.CreateLoginRecordStringString = delegate { return true; };
                var calledSetCurrentUser = false;
                ShimCurrentUser.SetInstanceString = delegate { calledSetCurrentUser = true; };
                ShimCurrentUser.Clear = delegate { };
                ShimCurrentUser.SessionInstanceGet = delegate { return new ShimCurrentUser(); };
                ShimLoginModel.AllInstances.SyncWithOrImportDataFromASPPIErrorLoggingServiceString = (loginModel, errorLoggingService, userNameSentToLoginModel) =>
                {
                };
                var calledSetAuthCookie = false;
                ShimFormsAuthentication.SetAuthCookieStringBooleanString = delegate { calledSetAuthCookie = true; };

                // Given a user
                const string corpUserName = "******";
                const string corpPassword = "******";
                const string simplUserName = "******";
                const string simplPassword = "******";
                var requestStub = new StubHttpRequestBase();
                var contextStub = new StubHttpContextBase {RequestGet = () => requestStub};

                var calledUpdateHistoricalRecored = false;
                ShimUserRepository.AllInstances.UpdateHistoricalRecordStringString = delegate
                {
                    calledUpdateHistoricalRecored = true;
                    return true;
                };

                var userAssociationModel = new AssociationViewModel();

                // And has known corp credentials
                userAssociationModel.UserName = corpUserName;
                userAssociationModel.Password = corpPassword;

                // And has known SIMPL credentials
                userAssociationModel.SIMPLUserName = simplUserName;
                userAssociationModel.SIMPLPassword = simplPassword;

                var wasAttemptToLogUserInCalledForCorp = false;
                var wasAttemptToLogUserInCalledForSIMPL = false;
                ShimLoginModel.AllInstances.AttemptToLogUserInStringString = (loginModel, userName, password) =>
                {
                    if (wasAttemptToLogUserInCalledForCorp && wasAttemptToLogUserInCalledForSIMPL)
                    {
                        return new LoginModel();
                    }
                    if (userName == corpUserName && password == corpPassword)
                    {
                        wasAttemptToLogUserInCalledForCorp = true;
                        return new LoginModel()
                        {
                            Message = SIMPL.Models.Code.Constants.Areas.Common.LoginModel.AuthenticationResultMessages.NoUserRoles
                        };
                    }
                    if (userName == simplUserName && password == simplPassword)
                    {
                        wasAttemptToLogUserInCalledForSIMPL = true;
                        return new LoginModel();
                    }
                    return new LoginModel()
                    {
                        Errors = true,
                        Message = SIMPL.Models.Code.Constants.Areas.Common.LoginModel.AuthenticationResultMessages.UnknownResult
                    };
                };

                // And corp username doesn’t match SIMPL username
                // When submitting the association form
                ShimUserManagement.AllInstances.UpdateUsernameStringString = delegate { return UserManagement.UpdateUsernameResult.Success; };
                LoginControllerForTests.ControllerContext = new ControllerContext { HttpContext = contextStub };
                var userAssociationResult = LoginControllerForTests.UserNameAssociation(userAssociationModel);

                // Then usernames are associated
                Assert.IsTrue(wasAttemptToLogUserInCalledForCorp, "Corp credential were not Authorized");
                Assert.IsTrue(wasAttemptToLogUserInCalledForSIMPL, "SIMPL credentials were not Authorized");
                Assert.IsTrue(calledUpdateHistoricalRecored, "UpdateHistoricalRecords was not called");
                Assert.IsNotNull(userAssociationResult);
                #pragma warning disable 183
                // ReSharper generates a warning on the next line, but having this check will guarantee that the return type is checked before the other asserts
                Assert.IsTrue(userAssociationResult is ActionResult, "The return from the UserLogin action method was not a ActionResult");
                #pragma warning restore 183
                Assert.IsTrue(userAssociationResult is RedirectResult, "The return from the UserLogin action method was not a RedirectResult");

                // And user is logged in
                Assert.IsTrue(calledSetCurrentUser, "The set CurrentUser was never called");
                Assert.IsTrue(calledSetAuthCookie, "The set Authorization cookie was never called");

                // And a message is displayed stating “Username association successful! Please use your corp credentials for future logins to SIMPL.”
                var redirectResult = userAssociationResult as RedirectResult;
                Assert.AreEqual("~/SIMPLNET/Search", redirectResult.Url, "The redirect URL was not the search page which should be called when you have a successful login");
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AssociationModel" /> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="service">The service.</param>
        /// <param name="configurationHelper">The configuration helper.</param>
        /// <param name="translator">The translator.</param>
        /// <param name="pluginManager">The plugin manager.</param>
        /// <param name="model">The model.</param>
        public AssociationModel(
            INotificationManager logger,
            ISonarRestService service,
            IConfigurationHelper configurationHelper,
            ISQKeyTranslator translator,
            IPluginManager pluginManager,
            SonarQubeViewModel model)
        {
            this.keyTranslator = translator;
            this.pluginManager = pluginManager;
            this.model = model;
            this.configurationHelper = configurationHelper;
            this.logger = logger;
            this.sonarService = service;

            // start view model
            this.associationViewModel = new AssociationViewModel(this);
        }
예제 #13
0
 public AddAssociationCommand(ObservableCollection <AssociationViewModel> _associations,
                              AssociationViewModel _association)
 {
     associations = _associations;
     association  = _association;
 }
        public ActionResult AssociationSave(AssociationViewModel viewModel, HttpPostedFileBase Image)
        {
            SessionKontrol();
            if (_users != null)
            {
                try
                {
                    if (viewModel.Image == null)
                    {
                        viewModel.Image = "0";
                    }
                    var isValid = Validate(viewModel, new AssociationValidator(), ModelState);
                    if (isValid)
                    {
                        if (viewModel.Id == 0)
                        {
                            UploadFiles(Image);
                            viewModel.Image  = imagename;
                            viewModel.Status = true;

                            if (_AssociationServices.GetAll().Count() == 0)
                            {
                                viewModel.Count = 0;
                            }

                            else
                            {
                                viewModel.Count = _AssociationServices.GetAll().OrderByDescending(x => x.Count).First().Count;
                            }


                            _AssociationServices.Add(viewModel);
                        }
                        else
                        {
                            var getimg = _AssociationServices.Get(viewModel.Id).Image;
                            if (viewModel.Image == "0")
                            {
                                viewModel.Image  = getimg;
                                viewModel.Status = true;
                                _AssociationServices.Update(viewModel);
                            }
                            else
                            {
                                UploadFiles(Image);
                                viewModel.Image = "/Areas/Login/Assets/images/" + imagename;
                                _AssociationServices.Update(viewModel);
                            }
                        }
                    }
                    else
                    {
                        if (viewModel.Id == 0)
                        {
                            return(View("associationadd", viewModel));
                        }
                        else
                        {
                            return(View("associationdetail", viewModel));
                        }
                    }
                }
                catch (Exception)
                {
                    return(View(ViewForm, viewModel));
                }
                _unitOfWork.SaveChanges();
                return(RedirectToAction("AssociationList", "Association"));
            }
            else
            {
                return(RedirectToAction("Index", "Login"));
            }
        }