public bool UpdateFoodBank(FoodBank foodBank) { var retVal = false; try { var client = new RestClient(ConfigurationManager.AppSettings["WebApiBaseUrlV1"]); var request = new RestRequest("api/v1/FoodBanks/", Method.PUT); request.AddParameter("Authorization", AuthorizationInformation, ParameterType.HttpHeader); request.AddJsonBody(foodBank); var response = client.Execute(request); if (response != null && response.StatusCode == HttpStatusCode.OK) { retVal = true; } else { retVal = false; } } catch (Exception ex) { LastError = ex; } return(retVal); }
private static Attachment CreateFoodbankPickupCardAttachment(FoodBank foodBank) { var allHours = foodBank.PickupHours.Select(dh => $"\r{dh.Day} {dh.Hours}") .Aggregate((string prev, string curr) => prev + ", " + curr); var cardText = $"**{foodBank.Name}**\r{foodBank.PickupNotes}\r**Hours** {allHours}"; return(new HeroCard(cardText).ToAttachment()); }
public ActionResult DeleteConfirmed(int id) { FoodBank foodBank = db.FoodBanks.Find(id); db.FoodBanks.Remove(foodBank); db.SaveChanges(); return(RedirectToAction("Index")); }
public PartialViewResult UpdateFoodBank(FoodBank foodBank) { var repository = new FoodBanksRepository(); repository.UpdateFoodBank(foodBank); var model = repository.GetFoodBank(foodBank.Id); return(PartialView("Partials/FoodBankTableRow", model.FoodBank)); }
public PartialViewResult CreateFoodBank(FoodBank foodBank) { var repository = new FoodBanksRepository(); repository.CreateFoodBank(foodBank); var model = repository.GetFoodBanks(); return(PartialView("Partials/FoodBanksTable", model)); }
public ActionResult Edit([Bind(Include = "UserId,NotificationPreference,id,name,phone,email,address1,address2,address3,address4,city,state,zip,IsActive")] FoodBank foodBank) { if (ModelState.IsValid) { db.Entry(foodBank).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(foodBank)); }
public ActionResult Edit([Bind(Include = "Id,Address,Email,Name,WebsiteURL,Latitude,ManagerEmail,Longtitude")] FoodBank foodBank) { if (ModelState.IsValid) { db.Entry(foodBank).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(foodBank)); }
public ActionResult Create([Bind(Include = "id,name,phone,email,address1,address2,address3,address4,city,state,zip")] FoodBank foodBank) { if (ModelState.IsValid) { db.FoodBanks.Add(foodBank); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(foodBank)); }
public ActionResult Create([Bind(Include = "Id,Address,Email,Name,WebsiteURL,Latitude,ManagerEmail,Longtitude")] FoodBank foodBank) { if (ModelState.IsValid) { db.FoodBanks.Add(foodBank); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(foodBank)); }
// GET: FoodBanks/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FoodBank foodBank = db.FoodBanks.Find(id); if (foodBank == null) { return(HttpNotFound()); } return(View(foodBank)); }
public FoodBanksModel GetFoodBanks(int start = 0, int total = 5) { var retVal = new FoodBanksModel(); try { var client = new RestClient(ConfigurationManager.AppSettings["WebApiBaseUrlV1"]); var request = new RestRequest("api/v1/FoodBanks/", Method.GET); request.AddParameter("Authorization", AuthorizationInformation, ParameterType.HttpHeader); request.AddParameter("offset", start); request.AddParameter("limit", total); var response = client.Execute <JsonReturn>(request); if (response != null && response.Data != null) { JsonReturn jReturn = response.Data; var data = (RestSharp.JsonArray)jReturn.Result; //Main data. var banks = new List <FoodBank>(); foreach (var item in data) { var result = (System.Collections.Generic.Dictionary <string, object>)item; var bank = new FoodBank(); if (result["addr1"] != null) { bank.Addr1 = result["addr1"].ToString(); } if (result["addr2"] != null) { bank.Addr2 = result["addr2"].ToString(); } if (result["city"] != null) { bank.City = result["city"].ToString(); } if (result["created"] != null) { bank.Created = DateTime.Parse(result["created"].ToString()); } if (result["donationCount"] != null) { bank.DonationCount = int.Parse(result["donationCount"].ToString()); } if (result["id"] != null) { bank.Id = int.Parse(result["id"].ToString()); } if (result["name"] != null) { bank.Name = result["name"].ToString(); } if (result["postal"] != null) { bank.Postal = result["postal"].ToString(); } if (result["state"] != null) { bank.State = result["state"].ToString(); } if (result["volunteerCount"] != null) { bank.VolunteerCount = int.Parse(result["volunteerCount"].ToString()); } banks.Add(bank); } retVal.Links = (List <Link>)jReturn.Links; //Links. //Get header(s). foreach (var header in response.Headers) { if (header.Name != "X-Total-Count") { continue; } retVal.TotalFoodBanks = int.Parse(header.Value.ToString()); break; } retVal.FoodBanks = banks; } } catch (Exception ex) { retVal = new FoodBanksModel(); } return(retVal); }