public ActionResult Delete(int id, AutoApproval autoApproval, bool showAll = false) { var autoApprovalToDelete = _autoApprovalRepository.GetNullableById(id); if (autoApprovalToDelete == null) { return(this.RedirectToAction(a => a.Index(showAll))); } if (autoApprovalToDelete.User.Id != CurrentUser.Identity.Name) { ErrorMessage = "No Access"; return(this.RedirectToAction <ErrorController>(a => a.Index())); } if (autoApprovalToDelete.IsActive) { autoApprovalToDelete.IsActive = false; _autoApprovalRepository.EnsurePersistent(autoApprovalToDelete); Message = "AutoApproval Deactivated Successfully"; } return(this.RedirectToAction(a => a.Index(showAll))); }
public ActionResult Create(AutoApproval autoApproval, bool showAll = false) { autoApproval.Equal = !autoApproval.LessThan; //only one can be true, the other must be false autoApproval.User = _userRepository.GetNullableById(CurrentUser.Identity.Name); ModelState.Clear(); autoApproval.TransferValidationMessagesTo(ModelState); if (autoApproval.Expiration.HasValue && autoApproval.Expiration.Value.Date <= DateTime.UtcNow.ToPacificTime().Date) { ModelState.AddModelError("AutoApproval.Expiration", "Expiration date has already passed"); } autoApproval.IsActive = true; if (ModelState.IsValid) { _autoApprovalRepository.EnsurePersistent(autoApproval); Message = "AutoApproval Created Successfully"; if (autoApproval.Expiration.HasValue && autoApproval.Expiration.Value.Date <= DateTime.UtcNow.ToPacificTime().Date.AddDays(5)) { Message = Message + " Warning, will expire in 5 days or less"; } return(this.RedirectToAction(a => a.Index(showAll))); } else { var viewModel = AutoApprovalViewModel.Create(Repository, CurrentUser.Identity.Name); viewModel.AutoApproval = autoApproval; ViewBag.ShowAll = showAll; ViewBag.IsCreate = true; return(View(viewModel)); } }
private PSPrivateLinkService CreatePSPrivateLinkService() { var psPrivateLinkService = new PSPrivateLinkService { Name = Name, ResourceGroupName = ResourceGroupName, Location = Location }; psPrivateLinkService.LoadBalancerFrontendIpConfigurations = LoadBalancerFrontendIpConfiguration?.ToList(); psPrivateLinkService.IpConfigurations = IpConfiguration?.ToList(); if (Visibility != null) { psPrivateLinkService.Visibility = new PSPrivateLinkServiceResourceSet(); psPrivateLinkService.Visibility.Subscriptions = Visibility.ToList(); } if (AutoApproval != null) { psPrivateLinkService.AutoApproval = new PSPrivateLinkServiceResourceSet(); psPrivateLinkService.AutoApproval.Subscriptions = AutoApproval.ToList(); } var plsModel = NetworkResourceManagerProfile.Mapper.Map <MNM.PrivateLinkService>(psPrivateLinkService); plsModel.Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true); this.PrivateLinkServiceClient.CreateOrUpdate(ResourceGroupName, Name, plsModel); var getPrivateLinkService = GetPrivateLinkService(ResourceGroupName, Name); return(getPrivateLinkService); }
public ActionResult Create(AutoApproval autoApproval, bool showAll = false) { autoApproval.Equal = !autoApproval.LessThan; //only one can be true, the other must be false autoApproval.User = _userRepository.GetNullableById(CurrentUser.Identity.Name); ModelState.Clear(); autoApproval.TransferValidationMessagesTo(ModelState); if(autoApproval.Expiration.HasValue && autoApproval.Expiration.Value.Date <= DateTime.UtcNow.ToPacificTime().Date) { ModelState.AddModelError("AutoApproval.Expiration", "Expiration date has already passed"); } autoApproval.IsActive = true; if (ModelState.IsValid) { _autoApprovalRepository.EnsurePersistent(autoApproval); Message = "AutoApproval Created Successfully"; if(autoApproval.Expiration.HasValue && autoApproval.Expiration.Value.Date <= DateTime.UtcNow.ToPacificTime().Date.AddDays(5)) { Message = Message + " Warning, will expire in 5 days or less"; } return this.RedirectToAction(a => a.Index(showAll)); } else { var viewModel = AutoApprovalViewModel.Create(Repository, CurrentUser.Identity.Name); viewModel.AutoApproval = autoApproval; ViewBag.ShowAll = showAll; ViewBag.IsCreate = true; return View(viewModel); } }
public void WhenIDeleteAnAutoApproval_ThenItIsDeteled() { _autoApprovalRepository.Create(_autoApproval); AutoApproval retrievedAutoApproval = _autoApprovalRepository.GetAutoApproval(_autoApproval.Id); _autoApprovalRepository.Delete(_autoApproval); AutoApproval autoApproval = _autoApprovalRepository.GetAutoApproval(retrievedAutoApproval.Id); autoApproval.Should().BeNull(); }
public static AutoApproval AutoApproval(int? i) { var rtResult = new AutoApproval(); rtResult.IsActive = true; rtResult.LessThan = true; rtResult.MaxAmount = (decimal) 10.77; rtResult.TargetUser = CreateValidEntities.User(98); rtResult.User = CreateValidEntities.User(55); return rtResult; }
public static AutoApproval AutoApproval(int?i) { var rtResult = new AutoApproval(); rtResult.IsActive = true; rtResult.LessThan = true; rtResult.MaxAmount = (decimal)10.77; rtResult.TargetUser = CreateValidEntities.User(98); rtResult.User = CreateValidEntities.User(55); return(rtResult); }
public virtual ActionResult Edit(int autoApprovalId, string docTypeCode) { AutoApproval autoApproval = new AutoApproval(); IList <AutoApproval> autoApprovals = new List <AutoApproval>(); if (autoApprovalId > 0) { autoApproval = this._autoApprovalService.GetAutoApproval(autoApprovalId); } else { autoApprovals = this._autoApprovalService.GetAutoApprovals(docTypeCode); } var docTypes = _docTypeService.GetDocTypes(); var subDocTypes = this._subDocTypeService.GetSubDocTypes(); var manCos = _manCoService.GetManCos(); var model = new EditAutoApprovalViewModel(); if (autoApprovalId > 0) { model.ManCoId = autoApproval.ManCoId; model.DocTypeId = autoApproval.DocTypeId; model.SubDocTypeId = autoApproval.SubDocTypeId; } else { model.ManCoId = autoApprovals.First().ManCoId; model.DocTypeId = autoApprovals.First().DocTypeId; model.SubDocTypeId = -1; } model.DocTypeCode = docTypeCode; model.AddManCos(manCos); model.AddDocTypes(docTypes); model.AddSubDocTypes(subDocTypes); model.SubDocTypes = model.SubDocTypes.FindAll(x => x.DocTypeViewModel.Id == model.DocTypeId); model.SubDocTypes.Insert(0, new SubDocTypeViewModel() { Code = "All", Id = -1 }); return(this.View(model)); }
public void Setup() { _transactionScope = new TransactionScope(); _autoApprovalRepository = new AutoApprovalRepository(ConfigurationManager.ConnectionStrings["Unity"].ConnectionString); _docTypeRepository = new DocTypeRepository(ConfigurationManager.ConnectionStrings["Unity"].ConnectionString); _subDocTypeRepository = new SubDocTypeRepository(ConfigurationManager.ConnectionStrings["Unity"].ConnectionString); _manCoRepository = new ManCoRepository(ConfigurationManager.ConnectionStrings["Unity"].ConnectionString); _docType = BuildMeA.DocType("code", "description"); _manCo1 = BuildMeA.ManCo("code1", "description1"); _manCo2 = BuildMeA.ManCo("code2", "description2"); _subDocType1 = BuildMeA.SubDocType("code 1", "description 1").WithDocType(_docType); _subDocType2 = BuildMeA.SubDocType("code 2", "description 3").WithDocType(_docType); _autoApproval = BuildMeA.AutoApproval().WithDocType(_docType).WithSubDocType(_subDocType1).WithManCo(_manCo1); _autoApproval2 = BuildMeA.AutoApproval().WithDocType(_docType).WithSubDocType(_subDocType2).WithManCo(_manCo2); _autoApproval3 = BuildMeA.AutoApproval().WithDocType(_docType).WithSubDocType(_subDocType2).WithManCo(_manCo1); }
public ActionResult Edit(int id, AutoApproval autoApproval, bool showAll = false) { var autoApprovalToEdit = _autoApprovalRepository.GetNullableById(id); if (autoApprovalToEdit == null) { return(this.RedirectToAction(a => a.Index(showAll))); } if (autoApprovalToEdit.User.Id != CurrentUser.Identity.Name) { ErrorMessage = "No Access"; return(this.RedirectToAction <ErrorController>(a => a.Index())); } TransferValues(autoApproval, autoApprovalToEdit); autoApprovalToEdit.Equal = !autoApprovalToEdit.LessThan; ModelState.Clear(); autoApprovalToEdit.TransferValidationMessagesTo(ModelState); if (ModelState.IsValid) { _autoApprovalRepository.EnsurePersistent(autoApprovalToEdit); Message = "AutoApproval Edited Successfully"; return(this.RedirectToAction(a => a.Index(showAll))); } else { var viewModel = AutoApprovalViewModel.Create(Repository, CurrentUser.Identity.Name); viewModel.AutoApproval = autoApprovalToEdit; ViewBag.ShowAll = showAll; ViewBag.IsCreate = false; return(View(viewModel)); } }
/// <summary> /// Transfer editable values from source to destination /// </summary> private static void TransferValues(AutoApproval source, AutoApproval destination) { Mapper.Map(source, destination); }
public ActionResult Edit(int id, AutoApproval autoApproval, bool showAll = false) { var autoApprovalToEdit = _autoApprovalRepository.GetNullableById(id); if (autoApprovalToEdit == null) { return this.RedirectToAction(a => a.Index(showAll)); } if(autoApprovalToEdit.User.Id != CurrentUser.Identity.Name) { ErrorMessage = "No Access"; return this.RedirectToAction<ErrorController>(a => a.Index()); } TransferValues(autoApproval, autoApprovalToEdit); autoApprovalToEdit.Equal = !autoApprovalToEdit.LessThan; ModelState.Clear(); autoApprovalToEdit.TransferValidationMessagesTo(ModelState); if (ModelState.IsValid) { _autoApprovalRepository.EnsurePersistent(autoApprovalToEdit); Message = "AutoApproval Edited Successfully"; return this.RedirectToAction(a => a.Index(showAll)); } else { var viewModel = AutoApprovalViewModel.Create(Repository, CurrentUser.Identity.Name); viewModel.AutoApproval = autoApprovalToEdit; ViewBag.ShowAll = showAll; ViewBag.IsCreate = false; return View(viewModel); } }
public ActionResult Delete(int id, AutoApproval autoApproval, bool showAll = false) { var autoApprovalToDelete = _autoApprovalRepository.GetNullableById(id); if (autoApprovalToDelete == null) { return this.RedirectToAction(a => a.Index(showAll)); } if(autoApprovalToDelete.User.Id != CurrentUser.Identity.Name) { ErrorMessage = "No Access"; return this.RedirectToAction<ErrorController>(a => a.Index()); } if(autoApprovalToDelete.IsActive) { autoApprovalToDelete.IsActive = false; _autoApprovalRepository.EnsurePersistent(autoApprovalToDelete); Message = "AutoApproval Deactivated Successfully"; } return this.RedirectToAction(a => a.Index(showAll)); }
private void SetUpVariables() { _manCo1 = new ManCo { Id = 1 }; _manCo2 = new ManCo { Id = 2 }; _manCo3 = new ManCo { Id = 3 }; this._manCos = new List <ManCo>(); this._manCos.Add(_manCo1); this._manCos.Add(_manCo2); this._manCos.Add(_manCo3); _docType1 = new DocType { Id = 1, Code = "Code1" }; _docType2 = new DocType { Id = 2, Code = "Code2" }; _docType3 = new DocType { Id = 3, Code = "Code3" }; this._docTypes = new List <DocType>(); this._docTypes.Add(_docType1); this._docTypes.Add(_docType2); this._docTypes.Add(_docType3); this._subDocType1 = new SubDocType { Id = 1, DocType = _docType1, Code = "SubCode1" }; this._subDocType2 = new SubDocType { Id = 2, DocType = _docType1, Code = "subCode2" }; this._subDocType3 = new SubDocType { Id = 3, DocType = _docType1, Code = "SubCode3" }; this._subDocType4 = new SubDocType { Id = 4, DocType = _docType2, Code = "SubCode4" }; this._subDocType5 = new SubDocType { Id = 5, DocType = _docType2, Code = "SubCode5" }; this._subDocType6 = new SubDocType { Id = 6, DocType = _docType3, Code = "SubCode6" }; this._subDocType7 = new SubDocType { Id = 7, DocType = _docType3, Code = "SubCode7" }; this._subDocType8 = new SubDocType { Id = 8, DocType = _docType3, Code = "SubCode8" }; this._subDocTypes = new List <SubDocType>(); this._subDocTypes.Add(_subDocType1); this._subDocTypes.Add(_subDocType2); this._subDocTypes.Add(_subDocType3); this._subDocTypes.Add(_subDocType4); this._subDocTypes.Add(_subDocType5); this._subDocTypes.Add(_subDocType6); this._subDocTypes.Add(_subDocType7); this._subDocTypes.Add(_subDocType8); this._approval1 = new AutoApproval { Id = 1, DocType = _docType1, SubDocType = _subDocType1, Manco = _manCo1 }; this._approval2 = new AutoApproval { Id = 2, DocType = _docType1, SubDocType = _subDocType2, Manco = _manCo1 }; this._approval3 = new AutoApproval { Id = 3, DocType = _docType1, SubDocType = _subDocType3, Manco = _manCo1 }; this._approval4 = new AutoApproval { Id = 4, DocType = _docType2, SubDocType = _subDocType4, Manco = _manCo1 }; this._approval5 = new AutoApproval { Id = 5, DocType = _docType3, SubDocType = _subDocType7, Manco = _manCo1 }; this._approvals = new List <AutoApproval>(); this._approvals.Add(_approval1); this._approvals.Add(_approval2); this._approvals.Add(_approval3); this._approvals.Add(_approval4); this._approvals.Add(_approval5); }