public bool SendMail(CandidateExamBookingDetail candidateExamBookingDetail) { try { string message = ""; //Here we will save data to the database DateTime bookedDate = Convert.ToDateTime(candidateExamBookingDetail.BookedDate); string slotname = db.ExamSlots.Where(s => s.SlotId == candidateExamBookingDetail.SlotId).FirstOrDefault().SlotName; string ToEmail = db.CandidateDetails.Where(c => c.CandidateId == candidateExamBookingDetail.CandidateId).FirstOrDefault().Email; //check username available byte[] bytes = null; MailModel mm = new Models.MailModel(); mm.To = ToEmail; mm.From = "*****@*****.**"; mm.Body = "Dear " + candidateExamBookingDetail.CandidateDetail.FirstName + ", <br /> <br />Thank you for booking exam with TADE. <br /><br />Your exam has been booked on " + bookedDate.ToString("dd/MM/yyyy") + " at " + slotname + ".<br /><br /><u>To attend the exam:</u><br /><br />Please read the registration confirmation email for exam details.<br /><br /> Kind Regards <br /> TADE Admin Team"; mm.Subject = "TADE exam booking confirmation"; message = "Exam booking confirmation"; SendMailBLL sm = new SendMailBLL(); sm.SendMail(mm, bytes); return(true); } catch (Exception ex) { return(false); } }
public JsonResult BookExam([Bind(Include = "BookingId,CandidateId,BookedDate,SlotId")] CandidateExamBookingDetail candidateExamBookingDetail) { string message = ""; //Here we will save data to the database try { int candidateId = Convert.ToInt32(Session["CandidateId"]); if (candidateId != 0) { DateTime exambookdate = Convert.ToDateTime(candidateExamBookingDetail.BookedDate); exambookdate = Convert.ToDateTime(exambookdate.ToShortDateString()); // candidateExamBookingDetail.BookedDate = exambookdate; candidateExamBookingDetail.CandidateId = candidateId; candidateExamBookingDetail.Status = true; CandidateExamBookingDetail candidateExamBookingDetl = candDal.CandidateExamBookingDetailByCandidateId(candidateExamBookingDetail.CandidateId); if (candidateExamBookingDetl == null) { candDal.SaveCandidateExamBookingDetails(candidateExamBookingDetail); UpdateSeats(exambookdate, candidateExamBookingDetail.SlotId, -1); } else { if (candidateExamBookingDetl.SlotId == candidateExamBookingDetail.SlotId && candidateExamBookingDetl.BookedDate == candidateExamBookingDetail.BookedDate) { } else { UpdateSeats(Convert.ToDateTime(candidateExamBookingDetl.BookedDate), candidateExamBookingDetl.SlotId, 1); UpdateSeats(exambookdate, candidateExamBookingDetail.SlotId, -1); } candDal.UpdateCandidateExamBookingDetails(candidateExamBookingDetail); } if (exambookdate == Convert.ToDateTime(DateTime.Today.ToShortDateString())) { int ExaminerId = candDal.ExaminerDetailByStatus().ExaminerId; //TADEDBEntities candUpd = new TADEDBEntities(); string unidate = DateTime.Today.ToShortDateString(); string strunidate = unidate.Replace("/", ""); string uniquetoken = strunidate + ExaminerId.ToString(); CandidateDetail cd = candDal.CandidateDetailsById(candidateId); cd.CandidateId = candidateId; cd.Status = true; cd.ExaminerId = ExaminerId; cd.uniquetoken = uniquetoken; candDal.UpdateCandidateDetail(cd); } SendMail(candidateExamBookingDetail); message = "Success"; } } catch (Exception ex) { message = ex.ToString(); } return(Json(message)); // return new JsonResult { Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }