public void Remove(Cluster cluster) { if (cluster == null) throw new ArgumentNullException("cluster not passed to be deleted"); if (String.IsNullOrWhiteSpace(cluster.Name)) throw new ArgumentNullException("cluster name for cluster to be deleted can not be null"); _svc.RemoveCluster(cluster); }
// GET: Cluster Delete public ActionResult Delete(Cluster cluster) { Cluster removeCluster = _clusterSvc.Get(cluster.Id); _clusterSvc.Remove(removeCluster); return View("List", _clusterSvc.GetList().Select(CreateViewModel)); }
// GET: Cluster Delete public ActionResult Delete(Cluster cluster) { Cluster removeCluster = _clusterSvc.Get(cluster.Id); _clusterSvc.Remove(removeCluster); return RedirectToAction("List"); }
public ActionResult Create(Cluster cluster) { if (String.IsNullOrWhiteSpace(cluster.Name)) { ModelState.AddModelError("Name", "Cluster name has to be set!"); return View("Create", cluster); } var newCluster = new Cluster { Name = cluster.Name, }; if (cluster.Id == 0) { _clusterSvc.Create(cluster); } else { _clusterSvc.Update(cluster); } return View("List", _clusterSvc.GetList() .Select(CreateViewModel)); }
public ActionResult Create(Cluster cluster) { if (ModelState.IsValid) { bool clustedExists = _clusterSvc.GetList().Any(t => t.Name.Equals(cluster.Name, StringComparison.CurrentCultureIgnoreCase)); if (!clustedExists) { if (cluster.Id == 0) _clusterSvc.Create(cluster); else _clusterSvc.Update(cluster); return RedirectToAction("List"); } else { ModelState.AddModelError("Name", string.Format("The name '{0}' is already in use.", cluster.Name)); } } ViewBag.ClusterGroups = _clusterGroupSvc.GetList(); return View(cluster); }
public ClusterDto Create(Cluster c) { return new ClusterDto { Id = c.Id, Name = c.Name }; }
private static ClusterViewModel CreateViewModel(Cluster cluster) { return new ClusterViewModel { Id = cluster.Id, Name = cluster.Name }; }
public Cluster Update(Cluster updatedCluster) { if (_svc.Clusters.Any(d => d.Name == updatedCluster.Name)) throw new ClusterAlreadyExistsException(); var result = _svc.UpdateCluster(updatedCluster); return result; }
public void Init() { _disaster = new Disaster {Id = 0, IsActive = true, Name = "Sharknado"}; _cluster = new Cluster {Id = 1, Name = "Red Zone"}; _person = new Person {Id = 2, FirstName = "John", LastName = "Doe"}; _dataService = new Mock<IDataService>(); _dataService.Setup(x => x.Disasters).Returns(new EnumerableQuery<Disaster>(new[] {_disaster})); _dataService.Setup(x => x.Clusters).Returns(new EnumerableQuery<Cluster>(new[] {_cluster})); _dataService.Setup(x => x.Persons).Returns(new EnumerableQuery<Person>(new[] {_person})); _clusterCoordinatorService = new Services.ClusterCoordinatorService(_dataService.Object); }
public void Init() { _coordinatorId = 42; _notCoordinatorId = 10; _dataService = new Mock<IDataService>(); _disaster1 = new Disaster { Id = 1, IsActive = true, Name = "Sharknado" }; _disaster2 = new Disaster { Id = 2, IsActive = true, Name = "Ice Age" }; _cluster1 = new Cluster { Id = 2, Name = "Red Zone" }; _cluster2 = new Cluster { Id = 3, Name = "Other Cluster" }; _person1 = new Person { Id = 3, FirstName = "John", LastName = "Doe" }; _person2 = new Person { Id = 4, FirstName = "Richard", LastName = "Roe" }; _person3 = new Person { Id = 5, FirstName = "Little", LastName = "Toe" }; _dataService.Setup(x => x.Disasters).Returns(new EnumerableQuery<Disaster>(new[] { _disaster1, _disaster2 })); _dataService.Setup(x => x.Clusters).Returns(new EnumerableQuery<Cluster>(new[] { _cluster1, _cluster2 })); _dataService.Setup(x => x.Persons).Returns(new EnumerableQuery<Person>(new[] { _person1, _person2, _person3 })); _dataService.Setup(x => x.Commitments).Returns(new EnumerableQuery<Commitment>(new[] { new Commitment { DisasterId = _disaster1.Id, PersonId = _person1.Id }, new Commitment { DisasterId = _disaster1.Id, PersonId = _person2.Id }, new Commitment { DisasterId = _disaster2.Id, PersonId = _person3.Id } })); _clusterCoordinatorService = new Services.ClusterCoordinatorService(_dataService.Object); }
public void AddCluster(Cluster newCluster) { context.Clusters.Add(newCluster); context.SaveChanges(); }
public Cluster UpdateCluster(Cluster updatedCluster) { var result = context.Clusters.Find(updatedCluster.Id); if (result == null) throw new ClusterNotFoundException(); result.Name = updatedCluster.Name; context.SaveChanges(); return result; }
public void RemoveCluster(Cluster cluster) { // attach the cluster to delete to the context, if needed. Otherwise the remove/delete won't work var cluster2Del = context.Clusters.Local.FirstOrDefault(cc => cc.Id == cluster.Id); if (cluster2Del == null) context.Clusters.Attach(cluster); context.Clusters.Remove(cluster); context.SaveChanges(); }
public ActionResult Update(Cluster cluster) { if (String.IsNullOrWhiteSpace(cluster.Name)) { ModelState.AddModelError("Name", "Cluster name has to be set!"); return View("Create", cluster); } _clusterSvc.Update(cluster); return View("List", _clusterSvc.GetList() .Select(CreateViewModel)); }
// GET: Cluster Create public ActionResult Create() { var newCluster = new Cluster(); return View(newCluster); }
public ActionResult Update(Cluster cluster) { if (ModelState.IsValid) { bool clustedExists = _clusterSvc.GetList().Any(t => t.Name.Equals(cluster.Name, StringComparison.CurrentCultureIgnoreCase)); if (!clustedExists) { _clusterSvc.Update(cluster); return View("List", _clusterSvc.GetList().Select(CreateViewModel)); } else { ModelState.AddModelError("Name", string.Format("The name '{0}' is already in use.", cluster.Name)); } } return View("Create", cluster); }
// GET: Cluster Create public ActionResult Create() { Cluster newCluster = new Cluster(); ViewBag.ClusterGroups = _clusterGroupSvc.GetList(); return View(newCluster); }
public void GetVolunteersForDate_WithFilteredClustersForCoordinators_ReturnsOneCoordinator() { var firstPerson = new Person() { Id = 231 }; var secondPerson = new Person() { Id = 233 }; var disaster = new Disaster { Id = 1, IsActive = true }; var cluster = new Cluster {Id = 765}; initializeVolunteerCollection(firstPerson, secondPerson); initializeDisasterCollection(disaster); initializeClusterCollection(cluster); initializeCoordinatorCollection( new ClusterCoordinator { Id = 432, PersonId = firstPerson.Id, Person = firstPerson, DisasterId = disaster.Id, Disaster = disaster, Cluster = cluster, ClusterId = cluster.Id}, new ClusterCoordinator { Id = 345, PersonId = secondPerson.Id, Person = secondPerson, DisasterId = disaster.Id, Disaster = disaster }); initializeCommitmentCollection(new Commitment { DisasterId = disaster.Id, Disaster = disaster, PersonId = firstPerson.Id, Person = firstPerson, ClusterId = cluster.Id, Cluster = cluster, StartDate = new DateTime(2015, 1, 5), EndDate = new DateTime(2015, 1, 23) }, new Commitment { DisasterId = disaster.Id, Disaster = disaster, PersonId = secondPerson.Id, Person = secondPerson, StartDate = new DateTime(2015, 1, 5), EndDate = new DateTime(2015, 1, 20) }); var adminService = new AdminService(mockService.Object); var results = adminService.GetVolunteersForDate(1, new DateTime(2015, 1, 7), true, false, new[] { 765 }).ToArray(); Assert.AreEqual(1, results.Length); Assert.AreEqual(firstPerson, results[0]); }