public ActionResult Delete(Guid id) { Guid profileId = this.GetActiveProfileId(); Stack stack = _stackRepository.Find(id); if (stack == null) { return(RedirectToAction("Index")); } IEnumerable <Instance> instances = stack.InstanceIds.Select(x => _instanceRepository.Find(x)).Where(x => x != null); var model = new DeleteStackViewModel { SelectedProfileId = profileId, StackModel = new StackOverviewViewModel { Name = stack.Name, Description = stack.Description, CreateTime = stack.CreateTime }, InstanceModels = _mapper.Map <IEnumerable <Instance>, IEnumerable <InstanceOverviewViewModel> >(instances), }; return(View(model)); }
private static void Map(AwsStack src, Stack dest) { dest.Description = src.Description; dest.Name = src.StackName; dest.CreateTime = src.CreationTime; dest.ResourceId = src.StackId; dest.Status = src.StackStatus; dest.NeedsRefreshing = false; }
private void Persist(Stack stackToPersist, SaveMechanic saveMechanic) { switch (saveMechanic) { case SaveMechanic.Add: _stackRepository.Add(stackToPersist); break; case SaveMechanic.Update: _stackRepository.Update(stackToPersist); break; default: throw new InvalidOperationException("Unknown save mechanic. This should never happen."); } }
public void LoadStack(IAwsClient awsClient, AwsStack stack, string hostedZone, Guid profileId) { Stack dbStack = _stackRepository.FindAll().FirstOrDefault(x => x.Name == stack.StackName); IEnumerable <StackResource> stackResources = awsClient.StackService.GetResources(stack).ToList(); List <ResourceRecord> resourceRecords = GetResourceRecords(awsClient, stackResources, stack, hostedZone); List <Guid> instanceIds = GetInstanceIds(stackResources).ToList(); Stack stackToPersist = dbStack ?? new Stack(); SaveMechanic saveMechanic = dbStack == null ? SaveMechanic.Add : SaveMechanic.Update; Map(stack, stackToPersist); stackToPersist.ResourceRecords = resourceRecords; if (!stackToPersist.CreatedByApplication) { stackToPersist.InstanceIds = instanceIds; } stackToPersist.StackEvents = GetStackEvents(awsClient, stack); stackToPersist.OwnerProfileId = profileId; Persist(stackToPersist, saveMechanic); }
public JsonResult UpdateNotes(StackNotesViewModel stackNotesViewModel) { try { string currentUsername = _owinContext.Authentication.User.Identity.Name; Stack stack = _stackRepository.Find(stackNotesViewModel.StackId); bool userHasPermissionForProfile = _userProfileAccessManager.UserHasPermissionForProfile(currentUsername, stackNotesViewModel.OwnerProfileId); if (!userHasPermissionForProfile) { stackNotesViewModel.Error = "User does not have permission to use this profile."; } if (!string.IsNullOrEmpty(stack.OwnerUserName)) { // If the stack was created with StackIt.net (and thus was created with a specific user), // only allow that user to update the notes for the stack if (stack.OwnerUserName != currentUsername) { stackNotesViewModel.Error = "Only the user that created this stack may change its notes."; } } if (string.IsNullOrEmpty(stackNotesViewModel.Error)) { stack.Notes = stackNotesViewModel.Notes; _stackRepository.Update(stack); } } catch (Exception) { // TODO: Log the exception somewhere stackNotesViewModel.Error = "Something unexpected happened. Contact an administrator."; } return(new JsonResult { Data = stackNotesViewModel }); }