public ActionResult DeleteConfirmed(int id) { FoodDonation foodDonation = this.foodDonationService.GetById(id); this.foodDonationService.Delete(foodDonation); return(RedirectToAction("MyDonations")); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FoodDonation foodDonation = this.foodDonationService.GetById((int)id); if (foodDonation == null) { return(HttpNotFound()); } FoodDonationViewModel model = Mapper.Map <FoodDonation, FoodDonationViewModel>(foodDonation); if (User.IsInRole(GlobalConstants.RecipientRoleName)) { ApplicationUser user = this.currentUserProvider.Get(); Recipient recipient = this.recipientProfileService.GetByApplicationUserId(user.Id); var existingRequest = this.foodRequestService.GetByDonationIdAndRecipientId((int)id, recipient.Id); if (existingRequest == null) { ViewBag.showRequestForm = true; } } return(View(model)); }
// GET: Donors/FoodDonations/Edit/5 public ActionResult Edit(int?id) { ApplicationUser user = this.currentUserProvider.Get(); Donor donor = this.donorProfileService.GetByApplicationUserId(user.Id); FoodDonation foodDonation = this.foodDonationService.GetById((int)id); if (donor.Id != foodDonation.DonorId) { return(RedirectToAction("Index")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (foodDonation == null) { return(HttpNotFound()); } IEnumerable <FoodCategory> foodCategories = this.foodCategoryService.GetAll(); ViewBag.FoodCategoryId = new SelectList(foodCategories, "Id", "Name", foodDonation.FoodCategoryId); FoodDonationEditModel model = Mapper.Map <FoodDonation, FoodDonationEditModel>(foodDonation); return(View(model)); }
public void UpdateFoodDeliveredStatus(FoodDonation data) { firebaseClient = new FireSharp.FirebaseClient(firebaseConfig); data.IsDelivered = true; SetResponse setResponse = firebaseClient.Set("MoneyDonation/" + data._id, data); Debug.WriteLine("updated response"); }
public void AddFoodDonationToFirebase(FoodDonation food) { firebaseClient = new FireSharp.FirebaseClient(firebaseConfig); var data = food; PushResponse response = firebaseClient.Push("FoodDonation/", data); data._id = response.Result.name; SetResponse setResponse = firebaseClient.Set("FoodDonation/" + data._id, data); }
public void CreateFoodDonationToFirebase(FoodDonation food) { try { AddFoodDonationToFirebase(food); ModelState.AddModelError(string.Empty, "Submitted Successfully"); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); Debug.WriteLine("exception from Create food donation: " + ex.Message); } }
public void UpdateFoodConfirmationStatus(FoodDonation foodData) { firebaseClient = new FireSharp.FirebaseClient(firebaseConfig); Volunteer volunteer = (Volunteer)Session["volunteer"]; foodData.IsConfirmed = true; foodData.VolunteerName = volunteer.Name; foodData.VolunteerPhone = volunteer.Mobile; foodData.VolunteerEmail = volunteer.Email; SetResponse setResponse = firebaseClient.Set("FoodDonation/" + foodData._id, foodData); SendConfirmationMessageToDonor("food", foodData.Name, foodData.VolunteerName, foodData.VolunteerPhone, foodData.VolunteerEmail, foodData.DonatorEmail); Debug.WriteLine("updated response"); }
public ActionResult Create(FoodDonationRegisterModel model) { List <string> validImageTypes = new List <string>() { "image/gif", "image/jpeg", "image/pjpeg", "image/png" }; if (ModelState.IsValid) { if (model.ImageUpload != null && !validImageTypes.Contains(model.ImageUpload.ContentType)) { ModelState.AddModelError("", "Please choose either a GIF, JPG or PNG image."); ViewBag.FoodCategoryId = new SelectList(this.foodCategoryService.GetAll(), "Id", "Name", model.FoodCategoryId); return(View(model)); } if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0) { string uploadDir = "/Content/Images/Donations_Food"; //string imagePath = Path.Combine(Server.MapPath(uploadDir), model.ImageUpload.FileName); string extension = Path.GetExtension(model.ImageUpload.FileName); string imageFileName = String.Format( "Food-Donations-{0}{1}", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"), extension); string imagePath = Path.Combine(Server.MapPath(uploadDir), imageFileName); model.ImageUrl = uploadDir + "/" + imageFileName; model.ImageUpload.SaveAs(imagePath); } ApplicationUser user = this.currentUserProvider.Get(); Donor donor = this.donorProfileService.GetByApplicationUserId(user.Id); FoodDonation foodDonation = Mapper.Map <FoodDonationRegisterModel, FoodDonation>(model); foodDonation.DonorId = donor.Id; this.foodDonationService.Add(foodDonation); return(RedirectToAction("MyDonations")); } ViewBag.FoodCategoryId = new SelectList(this.foodCategoryService.GetAll(), "Id", "Name", model.FoodCategoryId); return(View(model)); }
public ActionResult Edit(FoodDonationEditModel model) { FoodDonation foodDonation = this.foodDonationService.GetById(model.Id); Mapper.Map <FoodDonationEditModel, FoodDonation>(model, foodDonation); if (ModelState.IsValid) { this.foodDonationService.Update(foodDonation); return(RedirectToAction("MyDonations")); } IEnumerable <FoodCategory> foodCategories = this.foodCategoryService.GetAll(); ViewBag.FoodCategoryId = new SelectList(foodCategories, "Id", "Name", foodDonation.FoodCategoryId); return(View(foodDonation)); }
// GET: Donors/FoodDonations/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FoodDonation foodDonation = this.foodDonationService.GetById((int)id); if (foodDonation == null) { return(HttpNotFound()); } var model = Mapper.Map <FoodDonation, FoodDonationViewModel>(foodDonation); return(View(model)); }
private List <FoodDonation> SeedFoodDonations(ApplicationDbContext context, List <FoodCategory> foodCategories, List <Donor> donors) { var foodDonations = new List <FoodDonation>(); if (context.FoodDonations.Any()) { return(foodDonations); } for (int i = 0; i < 20; i++) { for (int j = 1; j <= 20; j++) { var foodDonation = new FoodDonation(); var categoryIndex = this.randomGenerator.Next(0, foodCategories.Count); var foodCategory = foodCategories[categoryIndex]; foodDonation.Donor = donors[i]; foodDonation.FoodCategory = foodCategory; foodDonation.Name = foodCategory.Name; foodDonation.Quantity = j.ToString() + (j == 1 ? " item" : " items"); foodDonation.Description = foodCategory.Name; var imageIndex = this.randomGenerator.Next(0, images.Count); foodDonation.ImageUrl = images[imageIndex]; foodDonation.ExpirationDate = DateTime.Now.AddDays(j + 10); foodDonation.AvailableFrom = DateTime.Now; foodDonation.AvailableTo = foodDonation.ExpirationDate.AddDays(-3); foodDonation.CreatedOn = DateTime.Now; context.FoodDonations.Add(foodDonation); foodDonations.Add(foodDonation); } } context.SaveChanges(); return(foodDonations); }
// GET: Donors/FoodDonations/Edit/5 public ActionResult Edit(int?id) { FoodDonation foodDonation = this.foodDonationService.GetById((int)id); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (foodDonation == null) { return(HttpNotFound()); } IEnumerable <FoodCategory> foodCategories = this.foodCategoryService.GetAll(); ViewBag.FoodCategoryId = new SelectList(foodCategories, "Id", "Name", foodDonation.FoodCategoryId); FoodDonationEditModel model = Mapper.Map <FoodDonation, FoodDonationEditModel>(foodDonation); return(View(model)); }
// ================== deliver donation ============== public ActionResult DeliveredDonationByVolunteer(ConfirmDonation model) { string item_id = model.item_id; Debug.WriteLine(item_id); Debug.WriteLine("i'm triggering"); try { firebaseClient = new FireSharp.FirebaseClient(firebaseConfig); if (model.item_type == "food") { FirebaseResponse response = firebaseClient.Get("FoodDonation/" + item_id); FoodDonation data = JsonConvert.DeserializeObject <FoodDonation>(response.Body); UpdateFoodDeliveredStatus(data); } else if (model.item_type == "cloth") { FirebaseResponse response = firebaseClient.Get("ClothDonation/" + item_id); ClothDonation data = JsonConvert.DeserializeObject <ClothDonation>(response.Body); UpdateClothDeliveredStatus(data); } else if (model.item_type == "money") { FirebaseResponse response = firebaseClient.Get("MoneyDonation/" + item_id); MoneyDonation data = JsonConvert.DeserializeObject <MoneyDonation>(response.Body); UpdateMoneyDeliveredStatus(data); } } catch (Exception ex) { Debug.WriteLine("Exception from Food Donation confirmation: " + ex); } return(RedirectToAction("/Index2")); }
public async Task <ActionResult> FoodDonation(FoodDonation model) { try { RootObject userLoc = getAddress(model.latitude, model.longitude); /* Debug.WriteLine(userLoc.address.road); * Debug.WriteLine(userLoc.address.suburb); * Debug.WriteLine(userLoc.address.city); * Debug.WriteLine(userLoc.address.state_district); * Debug.WriteLine(userLoc.address.state); * Debug.WriteLine(userLoc.address.postcode); * Debug.WriteLine(userLoc.address.country); * Debug.WriteLine(userLoc.address.country_code); */ Donator donator = (Donator)Session["donator"]; model.DonatorName = donator.Name; model.DonatorEmail = donator.Email; model.DonatorPhone = donator.Mobile; model.Date = DateTime.Now; model.Place = userLoc.display_name; model.IsTaken = false; model.IsDelivered = false; model.IsConfirmed = false; /* ================== send e-mail to volunteer ================ */ var bodyMessage = "You have a notification for food donation"; var body = "<p>Email From: {0} ({1})</p><p>Message: </p><p>{2}</p>"; var message = new MailMessage(); var volunteerList = ReadVolunteerFromFirebase(); // recipient mail (we have to send the notification to all volunteer) foreach (var v in volunteerList) { message.To.Add(new MailAddress(v.Email)); } message.From = new MailAddress("*****@*****.**"); // sender mail message.Subject = "Notifications for food donation from Hunger Solver"; message.Body = string.Format(body, model.DonatorName, model.DonatorEmail, bodyMessage); message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { // the following information is fixed for gmail // for outlook the host should be "smtp-mail.outlook.com" // configuration for the Client var credential = new NetworkCredential { UserName = "******", // sender mail Password = "******" // sender pass }; smtp.Credentials = credential; smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; await smtp.SendMailAsync(message); } CreateFoodDonationToFirebase(model); return(this.Redirect("/Donation/FoodDonation")); } catch (Exception e) { Debug.WriteLine("Exception from FoodDonation Submit: " + e); } return(View()); }
public void Add(FoodDonation foodDonation) { this.foodDonationRepository.Add(foodDonation); this.foodDonationRepository.SaveChanges(); }
public void Delete(FoodDonation foodDonation) { this.foodDonationRepository.Delete(foodDonation); this.foodDonationRepository.SaveChanges(); }
public FoodDonation CreateFoodDonation(FoodDonation donation) { var createFoodDonation = Context.Add(donation); return(createFoodDonation.Entity); }