public async Task <ActionResult> ClothDonation(ClothDonation model) { try { RootObject userLoc = getAddress(model.latitude, model.longitude); Donator donator = (Donator)Session["donator"]; model.DonatorName = donator.Name; model.DonatorEmail = donator.Email; 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 cloth 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 cloth 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); } CreateClothDonationToFirebase(model); return(this.Redirect("/Donation/ClothDonation")); } catch (Exception e) { Debug.WriteLine("Exception from ClothDonation Submit: " + e); } return(View()); }
public void UpdateClothDeliveredStatus(ClothDonation data) { firebaseClient = new FireSharp.FirebaseClient(firebaseConfig); data.IsDelivered = true; SetResponse setResponse = firebaseClient.Set("MoneyDonation/" + data._id, data); Debug.WriteLine("updated response"); }
public void AddClothDonationToFirebase(ClothDonation cloth) { firebaseClient = new FireSharp.FirebaseClient(firebaseConfig); var data = cloth; PushResponse response = firebaseClient.Push("ClothDonation/", data); data._id = response.Result.name; SetResponse setResponse = firebaseClient.Set("ClothDonation/" + data._id, data); }
public void CreateClothDonationToFirebase(ClothDonation cloth) { try { AddClothDonationToFirebase(cloth); ModelState.AddModelError(string.Empty, "Submitted Successfully"); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); Debug.WriteLine("exception from Create cloth donation: " + ex.Message); } }
public void UpdateClothConfirmationStatus(ClothDonation data) { firebaseClient = new FireSharp.FirebaseClient(firebaseConfig); Volunteer volunteer = (Volunteer)Session["volunteer"]; data.IsConfirmed = true; data.VolunteerName = volunteer.Name; data.VolunteerPhone = volunteer.Mobile; data.VolunteerEmail = volunteer.Email; SetResponse setResponse = firebaseClient.Set("ClothDonation/" + data._id, data); SendConfirmationMessageToDonor("cloth", data.Name, data.VolunteerName, data.VolunteerPhone, data.VolunteerEmail, data.DonatorEmail); Debug.WriteLine("updated response"); }
// ================== 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")); }