public bool AddUpdateRoute(Route route) { bool success = true; using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey)) { PutAttributesRequest request = new PutAttributesRequest { DomainName = DomainName, ItemName = route.Id.ToString() }; request.Attribute.Add(new ReplaceableAttribute() { Name = "Name", Replace = true, Value = route.Name }); request.Attribute.Add(new ReplaceableAttribute() { Name = "Distance", Replace = true, Value = route.Distance.ToString() }); request.Attribute.Add(new ReplaceableAttribute() { Name = "Id", Replace = true, Value = route.Id.ToString() }); request.Attribute.Add(new ReplaceableAttribute() { Name = "LastTimeRidden", Replace = true, Value = route.LastTimeRidden.ToShortDateString() }); request.Attribute.Add(new ReplaceableAttribute() { Name = "Location", Replace = true, Value = route.Location }); try { PutAttributesResponse response = client.PutAttributes(request); } catch(Exception repositoryError) { success = false; } } return success; }
public Routes GetAllRoutes() { Routes routes = new Routes(); using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey)) { SelectRequest request = new SelectRequest().WithSelectExpression( string.Format("SELECT * FROM Routes ")); SelectResponse response = client.Select(request); foreach (Item item in response.SelectResult.Item) { string value = item.Attribute.GetValueByName("Id"); Route route = new Route { Id = Guid.Parse(item.Attribute.GetValueByName("Id")), Distance = item.Attribute.GetDoubleValueByName("Distance"), LastTimeRidden = item.Attribute.GetDateTimeValueByName("LastTimeRidden"), Name = item.Attribute.GetValueByName("Name"), Location = item.Attribute.GetValueByName("Location"), }; routes.Add(route); } } return routes; }
public bool AddRoute(Route route) { Errors.Clear(); if (string.IsNullOrWhiteSpace(route.Name)) { Errors.Add("Name is required"); } if (string.IsNullOrWhiteSpace(route.Location)) { Errors.Add("Location is required"); } if (route.Id == new Guid()) { Errors.Add("Invalid route Id"); } if (Errors.Count==0) { if (!RouteRepositoryInterface.AddUpdateRoute(route)) { Errors.Add("An error occurred saving this route."); } } return Errors.Count == 0; }
public ActionResult UpdateRoute(Route newRoute) { RouteRequestsInterface.AddRoute(newRoute); List<string> errors = RouteRequestsInterface.Errors; ViewData["Errors"] = errors; if (errors.Count==0) { ViewData["IsUpdate"] = true; } return View("AddUpdateRoute",newRoute); }
public Route GetRouteById(Guid id) { Errors.Clear(); Route route = new Route(); if (id == new Guid()) { Errors.Add("Invalid route Id"); } else { route = RoutesRepositoryInterface.GetRouteById(id); } return route; }
public Route GetRouteById(Guid routeId) { Route route = new Route(); using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey)) { SelectRequest request = new SelectRequest().WithSelectExpression( string.Format("SELECT * FROM Routes where Id = '{0}'", routeId)); SelectResponse response = client.Select(request); if (response.SelectResult.Item.Count>0) { route.Id = Guid.Parse(response.SelectResult.Item[0].Attribute.GetValueByName("Id")); route.Distance = response.SelectResult.Item[0].Attribute.GetDoubleValueByName("Distance"); route.LastTimeRidden = response.SelectResult.Item[0].Attribute.GetDateTimeValueByName("LastTimeRidden"); } } return route; }
public bool AddRoute(Route route) { throw new NotImplementedException(); }
public ActionResult AddRoute() { Route newRoute = new Route {Id = Guid.NewGuid()}; return View("AddUpdateRoute", newRoute); }