private static PassReference MapToPassReference(PassModel command) { return(new PassReference() { Id = command.Id }); }
public static void SetIds(PassModel passModel, IIdentityGeneratorResolver identityGeneratorResolver) { var identityGenerator = (identityGeneratorResolver ?? throw new ArgumentNullException(nameof(identityGeneratorResolver))) .Resolve <IPassRepository>(); passModel.Id = (passModel.Id == 0) ? identityGenerator.GetIdentities <PassIdIdentity>(1)[0].Id : passModel.Id; }
// GET: /UserSession/ public ActionResult Index() { PassModel model = Session["Exploit"] as PassModel; int idExploitation = model.idUser; ExploitationModel _exploitationModel = exploitationService.GetExploitationById(idExploitation); return(View("Index", _exploitationModel)); }
public ActionResult ChoixProjet() { PassModel model = TempData["Data"] as PassModel; List <ProjectModel> projetList = projetService.GetAll(model.idUser); if (model.admin) { return(PartialView("AdminProjectChoice", projetList)); } return(View("ChoixProjet", projetList)); }
public void WhenTheUserPurchasesAPassFromATeacher() { var pass = new PassModel { PaymentStatus = PassPaymentStatus.Paid.ToString() }; var response = ApiCaller.Post <ActionReponse <UserModel> >(pass, Routes.GetPassPurchase(ScenarioCache.GetUserId(), ScenarioCache.GetId(ModelIdKeys.PassTemplateId))); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); }
// // GET: /Exploitation/ public ActionResult ChoixExploitation() { PassModel model = TempData["Project"] as PassModel; List <ExploitationModel> exploitList = exploitationService.GetExploitationsByIdProject(model.idUser); if (model.admin) { return(PartialView("AdminExploitationChoice", exploitList)); } return(View("ChoixExploitation", exploitList)); }
public void WhenTheUserPurchasesAPassThatDoesntExistFromATeacher() { var pass = new PassModel { PaymentStatus = PassPaymentStatus.Paid.ToString() }; var url = Routes.GetPassPurchase(ScenarioCache.GetUserId(), 2); var response = ApiCaller.Post <ActionReponse <UserModel> >(pass, url); ScenarioCache.StoreActionResponse(response); }
public IHttpActionResult Put([FromUri] int id, [FromBody] PassModel command) { // Check empty name if (string.IsNullOrWhiteSpace(command.Name)) { return(this.Error().InvalidParameters("No name was entered")); } if (!ModelState.IsValid) { return(this.Error().InvalidParameters("Invalid pass parameters")); } var pass = _passRepository.Get(id); if (pass == null) { return(NotFound()); } var pass2 = _passRepository.FindByName(command.Name, command.IsLibraried); if (pass2 != null && pass.Id != pass2.Id) { return(this.Error().InvalidParameters("Pass with such name already exists")); } if (_passInspectorService.InspectPassSalesAreaPriorities( command.PassSalesAreaPriorities, out string errorMessage)) { return(this.Error().InvalidParameters(errorMessage)); } List <string> breakExclusionsErrorMessages = new List <string>(); if (!BreakExclusionsValidations.DateTimeRangeIsValid(command.BreakExclusions, _salesAreaRepository.GetAll(), out breakExclusionsErrorMessages)) { return(this.Error().InvalidParameters(breakExclusionsErrorMessages)); } Mappings.ApplyToPass(pass, command, _mapper); IdUpdater.SetIds(pass, _identityGeneratorResolver); // Validate ValidateForSave(pass); // Save _passRepository.Update(pass); _passRepository.SaveChanges(); // Do not remove this, need to persist changes now so that we can return PassModel return(Ok(Mappings.MapToPassModel(pass, _passRepository, _mapper))); }
private static void PopulateEntity(Pass entity, PassModel instance) { entity.Id = instance.Id; entity.Cost = instance.Cost; entity.Description = instance.Description; entity.EndDate = instance.EndDate; entity.PassType = instance.PassType; entity.PaymentStatus = instance.PaymentStatus; entity.Note = instance.Note; entity.Owner = instance.Owner.ToEntity(); entity.PassStatistic = instance.PassStatistic.ToEntity(); entity.StartDate = instance.StartDate; }
public static Pass ToEntity(this PassModel instance) { if (instance.IsNull()) { return(null); } var pass = new Pass(); PopulateEntity(pass, instance); return(pass); }
public async Task <IActionResult> Create(PassModel model) { string username = model.username; string password = model.password; if (await IsValidUsernmeAndPassword(username, password)) { return(new ObjectResult(await GenerateToken(username))); } else { return(BadRequest()); } }
public IHttpActionResult Post(int userId, int passTemplateId, [FromBody] PassModel pass) { var userModel = new UserModel { Id = userId, Passes = pass.PutIntoList() }; var user = userModel.ToEntity(); var result = PerformAction <PurchasePass, User>(new PurchasePass(user) { PassTemplateId = passTemplateId }); return(new ActionResultToCreatedHttpActionResult <User, UserModel>(result, x => x.ToModel(), this) .Do()); }
private PassModel GetPassModel() { var model = new PassModel(); model.Id = 1; model.Name = "Name"; model.General = new List <GeneralModel>() { new GeneralModel() { RuleId = (int)RuleID.MinimumEfficiency, Value = "1" } }; model.Weightings = new List <WeightingModel>() { new WeightingModel() }; model.Tolerances = new List <ToleranceModel>() { new ToleranceModel() }; model.Rules = new List <PassRuleModel>() { new PassRuleModel() }; model.PassSalesAreaPriorities = new PassSalesAreaPriorityModel(); model.PassSalesAreaPriorities.StartTime = new TimeSpan(1, 1, 1); model.PassSalesAreaPriorities.EndTime = new TimeSpan(2, 2, 2); // NOTE: the below StartDate and EndDate are added since the tests were failing // The tests were failing since validations were added for StartDate and EndDate // but the test was not updated by the team member who did the change model.PassSalesAreaPriorities.StartDate = DateTime.Now; model.PassSalesAreaPriorities.EndDate = DateTime.Now.AddDays(6); model.PassSalesAreaPriorities.DaysOfWeek = "1111111"; model.PassSalesAreaPriorities.SalesAreaPriorities = new List <SalesAreaPriorityModel>() { new SalesAreaPriorityModel() { SalesArea = "sa1" } }; return(model); }
/// <summary> /// Updates Pass repository for passes /// </summary> /// <param name="scenario"></param> /// <param name="command"></param> /// <param name="deletedPassIds"></param> private void UpdatePassRepository(Scenario scenario, ScenarioModel command, List <int> deletedPassIds) { var updatedPasses = new List <Pass>(); var newPasses = new List <Pass>(); // Get changes for Pass repository for (int passIndex = 0; passIndex < scenario.Passes.Count; passIndex++) { PassReference passReference = scenario.Passes[passIndex]; PassModel passModel = command.Passes[passIndex]; Pass pass = passReference.Id == 0 ? null : _passRepository.Get(passReference.Id); if (pass == null) // New pass { pass = _mapper.Map <Pass>(passModel); pass.Id = passReference.Id; // Set in previous call to IdUpdater.SetIds Pass.ValidateForSave(pass); newPasses.Add(pass); } else // Update pass { Mappings.ApplyToPass(pass, passModel, _mapper); Pass.ValidateForSave(pass); updatedPasses.Add(pass); } } // Add/update updatedPasses.ForEach(currentPass => _passRepository.Update(currentPass)); newPasses.ForEach(currentPass => _passRepository.Add(currentPass)); // Delete passes if (deletedPassIds != null && deletedPassIds.Any()) { _passRepository.Remove(deletedPassIds); } }
public ActionResult LogOn(LogOnModel model, string returnUrl) { if (model.Utilisateur == "admin" && model.Mot_de_passe == "admin") { return(RedirectToAction("choixUtilisateur")); } else { LogOnModel _model = membershipService.GetByNamePasswd(model.Utilisateur, model.Mot_de_passe); if (_model != null) { TempData["Data"] = new PassModel { idUser = _model.UserIdentity, admin = false }; return(RedirectToAction("ChoixProjet", "Project")); //return PartialView("ChoixProjett", new PassModel { idUser = _model.UserIdentity, admin = false }); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); return(View(model)); } } }
public IHttpActionResult Post(int passTemplateId, [FromBody] PassModel pass) { return(Post(_currentUser.Id, passTemplateId, pass)); }
public static void Verify(PassModel expected, PassModel actual) { Assert.AreEqual(expected.StartDate, actual.StartDate); Assert.AreEqual(expected.EndDate, actual.EndDate); }
public static void ApplyToPass(Pass pass, PassModel command, IMapper mapper) { if (pass != null && command != null) { pass.Id = command.Id > 0 ? command.Id : pass.Id; pass.Name = command.Name; List <General> oldGenerals = new List <General>(); pass.General.ForEach(item => oldGenerals.Add(item)); pass.General.Clear(); foreach (GeneralModel generalModel in command.General) { General oldGeneral = oldGenerals.Find(item => item.RuleId == generalModel.RuleId); if (oldGeneral == null) { General general = MapToGeneral(generalModel); pass.General.Add(general); } else { ApplyToGeneral(oldGeneral, generalModel); pass.General.Add(oldGeneral); } } List <PassRule> oldRules = new List <PassRule>(); pass.Rules.ForEach(item => oldRules.Add(item)); pass.Rules.Clear(); foreach (PassRuleModel ruleModel in command.Rules) { PassRule oldRule = oldRules.Find(item => item.RuleId == ruleModel.RuleId); if (oldRule == null) // New rule { PassRule rule = MapToRule(ruleModel); pass.Rules.Add(rule); } else { ApplyToRule(oldRule, ruleModel); pass.Rules.Add(oldRule); } } #region pass.Tolerances List <Tolerance> oldTolerances = new List <Tolerance>(); pass.Tolerances.ForEach(item => oldTolerances.Add(item)); pass.Tolerances.Clear(); foreach (ToleranceModel toleranceModel in command.Tolerances) { Tolerance oldTolerance = oldTolerances.Find(item => item.RuleId == toleranceModel.RuleId); if (oldTolerance == null) // New rule { Tolerance tolerance = MapToTolerance(toleranceModel); pass.Tolerances.Add(tolerance); } else { ApplyToTolerance(oldTolerance, toleranceModel); pass.Tolerances.Add(oldTolerance); } } #endregion pass.Tolerances #region pass.RatingPoints pass.RatingPoints = command.RatingPoints.Select(x => mapper.Map <RatingPoint>(x)).ToList(); #endregion pass.RatingPoints #region pass.Weightings List <Weighting> oldWeightings = new List <Weighting>(); pass.Weightings.ForEach(item => oldWeightings.Add(item)); pass.Weightings.Clear(); foreach (WeightingModel weightingMode in command.Weightings) { Weighting oldWeighting = oldWeightings.Find(item => item.RuleId == weightingMode.RuleId); if (oldWeighting == null) // New rule { Weighting weighting = MapToWeighting(weightingMode); pass.Weightings.Add(weighting); } else { ApplyToWeighting(oldWeighting, weightingMode); pass.Weightings.Add(oldWeighting); } } #endregion pass.Weightings #region pass.ProgrammeRepetitions pass.ProgrammeRepetitions.Clear(); foreach (ProgrammeRepetitionModel programmeRepetitionMode in command.ProgrammeRepetitions) { ProgrammeRepetition programmeRepetition = MapToProgrammeRepetition(programmeRepetitionMode); pass.ProgrammeRepetitions.Add(programmeRepetition); } #endregion pass.ProgrammeRepetitions #region pass.BreakExclusions pass.BreakExclusions.Clear(); foreach (BreakExclusionModel breakExclusionMode in command.BreakExclusions) { BreakExclusion breakExclusion = MapToBreakExclusion(breakExclusionMode); pass.BreakExclusions.Add(breakExclusion); } #endregion pass.BreakExclusions #region pass.SlottingLimits pass.SlottingLimits.Clear(); foreach (SlottingLimitModel slottingLimitMode in command.SlottingLimits) { SlottingLimit slottingLimit = MapToSlottingLimit(slottingLimitMode); pass.SlottingLimits.Add(slottingLimit); } #endregion pass.SlottingLimits #region pass.PassSalesAreaPriorities pass.PassSalesAreaPriorities = MapToPassSalesAreaPriorities(command.PassSalesAreaPriorities); #endregion pass.PassSalesAreaPriorities } }
public static void ApplyToPassReference(PassReference passReference, PassModel command) { passReference.Id = (command.Id > 0 ? command.Id : passReference.Id); }