public async Task <IHttpActionResult> VerifyBloodRequest(string Id) { //check for validity of request var count = context.BepBloodRequests.Where(x => (x.Id == Id && x.Verified == false)).Count(); if (count == 0) { return(BadRequest("bad request or request already verified")); } else { BepBloodRequest donor; using (var db = new beplusContext()) {//when successful store data donor = db.BepBloodRequests.SingleOrDefault(x => x.Id == Id); donor.Verified = true; db.Entry(donor).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } int time; //TODO Check if emergency or non emergency, write code to increase the radius accordingly as per given time using jobs/threads if (donor.Emergency == true) { time = 360000; } else { time = 7200000; } //creating a new thread for sending out the requests Thread th = new Thread(() => funk(time, donor)); th.Start(); return(Ok("Your have been verified and your request has been initiated")); } }
public async Task <IHttpActionResult> ActivateDonor(string Id) { var count = context.BepDonors.Where(x => (x.Id == Id && x.Activated == true)).Count(); if (count == 1) { return(BadRequest("You are already registered. Please login using our application.")); } count = context.BepDonors.Where(x => (x.Id == Id && x.Activated == false)).Count(); if (count == 0) { return(BadRequest("An error has occured. Please try registering again.")); } else { using (var db = new beplusContext()) { BepDonor donor = db.BepDonors.SingleOrDefault(x => x.Id == Id); donor.Activated = true; db.Entry(donor).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(Ok("Your account has been activated! Please login using our app.")); } }
public async Task <IHttpActionResult> RegisterOfflineDonor(BepDonor input) { // Does the donor data exist? var count = context.BepDonors.Where(x => (x.Phone == input.Phone && x.OnlineStatus == true)).Count(); if (count > 0) { return(BadRequest("Phone number already registered!")); } count = context.BepDonors.Where(x => (x.Email == input.Email && x.OnlineStatus == true)).Count(); if (count > 0) { return(BadRequest("Email id already registered!")); } count = context.BepDonors.Where(x => (x.Email == input.Email || x.Phone == input.Phone)).Count(); if (count == 1) { using (var db = new beplusContext()) { BepDonor donor = db.BepDonors.SingleOrDefault(x => (x.Email == input.Email || x.Phone == input.Phone)); donor.Subscribed = true; donor.OnlineStatus = true; donor.Activated = true; donor.Password = input.Password; donor.LocationLat = input.LocationLat; donor.LocationLong = input.LocationLong; donor.EmergencyAvailability = input.EmergencyAvailability; db.Entry(donor).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(Ok("Donor registered successfully!")); } else { return(BadRequest("Email or Phone not registered!")); } }
public async Task <IHttpActionResult> HonorBloodRequest(string Id, string donorId) { //API call to accept a bloodrequest var count = context.BepBloodRequests.Where(x => (x.Id == Id && x.Honored == true)).Count(); //checking if honored or not by checking if x.id matches and x.honored is true.if count is one ->honored if (count == 1) { //Display message that another donor has already accepted the blood request return(BadRequest("Sorry request all ready honored.")); } else { using (var db = new beplusContext()) {//storing the info of the registered donor //donfound = true; BepBloodRequest bloodRequest = db.BepBloodRequests.SingleOrDefault(x => x.Id == Id); bloodRequest.Honored = true; BepDonor donor = db.BepDonors.Single(x => x.Id == donorId); bloodRequest.DonorId = donor.Id; bloodRequest.DonorEmail = donor.Email; bloodRequest.DonorImgurl = donor.Imgurl; bloodRequest.DonorName = donor.Name; bloodRequest.DonorId = donor.Id; db.Entry(bloodRequest).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); //Send the mail to the bloodRequest.recipientEmail saying the request was honored with name and location of the donor string msg = "<!DOCTYPE html><html><head></head><body><p>dear " + bloodRequest.RecipientName + " ,</br>your request has been accepted.the donor name is " + donor.Name + ".please click <a href=\"http://maps.google.com/maps?daddr=" + donor.LocationLat + "," + donor.LocationLong + "&ll=\">here</a> to view donors current location</br>Thank you.</p></body></html>"; Sender.SendMail(bloodRequest.RecipientEmail, "Donor found!", msg); string mail = "<!DOCTYPE html><html><head><style>table, th, td {border:1px solid black;border-collapse:collapse;}th, td {padding:5px;}</style></head><body><div style=\"border:5px solid #800000; padding:10px\"><div style=\"background-color:#800000;padding:20px\"><h1 style=\"color:white \">Welcome!</h1></div><p> dear" + " " + donor.Name + ",</p><p> a person needs blood please help him in this time of need. The details are as given below.</br>Thank you.</p><table style=\"width:100%\"><tbody><tr><td>name</td><td>" + bloodRequest.RecipientName + "</td></tr><tr><td>amount</td><td>" + bloodRequest.BloodUnits + "</td></tr><tr><td>type</td><td>" + bloodRequest.BloodType + "</td></tr><tr><td>hospital name</td><td>" + bloodRequest.HospitalName + "</td></tr><tr><td>hospital address</td><td>" + bloodRequest.HospitalAddress + "</td></tr></tbody></table></div><div></a></br>please click <a href=\"http://maps.google.com/maps?daddr=" + bloodRequest.LocationLat + "," + bloodRequest.LocationLong + "&ll=\">here</a> to view and navigate to recipients current location</div></body></html>"; Sender.SendMail(bloodRequest.DonorEmail, "Donor info", mail); } //confirming the donor that his request has been accepted return(Ok("Thank you for honoring blood request.please see the email.")); } }