public async Task <IHttpActionResult> PutDoctor(long id, Doctor doctor) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != doctor.doctorID) { return(BadRequest()); } db.Entry(doctor).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DoctorExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PutAspNetUser(string id, AspNetUser aspNetUser) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != aspNetUser.Id) { return(BadRequest()); } db.Entry(aspNetUser).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AspNetUserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <HttpResponseMessage> RemovePatientAlert(DeleteAlertModel model) { try { Alert alert = db.Alerts.Where(all => all.alertID == model.alertID && all.active == true).FirstOrDefault(); if (alert == null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Alert not found." }); response.ReasonPhrase = "Alert not found."; return(response); } alert.active = false;//Delete Operation changed alert.mb = model.userID; alert.md = System.DateTime.Now; db.Entry(alert).State = EntityState.Modified; await db.SaveChangesAsync(); } catch (Exception ex) { return(ThrowError(ex, "DeletePatientAlert in AlertsController.")); } response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = model.alertID, message = "" }); return(response); }
public async Task <HttpResponseMessage> AddPatientMedication(PatientMedication_Custom model) { Medication medication = new Medication(); try { if (model.medicineName == null || model.medicineName == "") { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Medicine name is not valid." }); return(response); } if (model.frequency == null || model.frequency == "") { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Frequency is not valid." }); return(response); } if (model.patientId == 0 || model.patientId == null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Patient ID is not valid." }); return(response); } medication = db.Medications.Where(m => m.patientId == model.patientId && m.medicineName.Trim() == model.medicineName.Trim() && m.active == true).FirstOrDefault(); if (medication == null) { medication = new Medication(); medication.active = true; medication.frequency = model.frequency; medication.patientId = model.patientId; medication.cd = System.DateTime.Now; medication.source = "S"; medication.reportedDate = System.DateTime.Now; medication.cb = medication.patientId.ToString(); medication.medicineName = model.medicineName; db.Medications.Add(medication); await db.SaveChangesAsync(); } else { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Medicine already exists." }); response.ReasonPhrase = "Medicine already exists."; return(response); } } catch (Exception ex) { return(ThrowError(ex, "AddPatientMedication in PatientMedicationController.")); } response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = medication.medicationID, message = "" }); return(response); }
public async Task <IHttpActionResult> PutSpeciallity(long id, Speciallity speciallity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != speciallity.speciallityID) { return(BadRequest()); } db.Entry(speciallity).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SpeciallityExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <HttpResponseMessage> addPatientFamilyHX(PatientFamilyHX_Custom model) { PatientFamilyHX phx = new PatientFamilyHX(); try { if (model.name == null || model.name == "") { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid familyHX." }); return(response); } if (model.patientID == null || model.patientID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid patient id." }); return(response); } phx = db.PatientFamilyHXes.Where(p => p.name.Trim() == model.name.Trim() && p.patientID == model.patientID).FirstOrDefault(); if (phx != null) { phx.relationship = model.relationship; phx.md = System.DateTime.Now; phx.mb = phx.patientID.ToString(); phx.active = true; db.Entry(phx).State = EntityState.Modified; await db.SaveChangesAsync(); response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = phx.fhxid, message = "" }); return(response); } if (phx == null) { phx = new PatientFamilyHX(); phx.active = true; phx.name = model.name; phx.relationship = model.relationship; phx.patientID = model.patientID; phx.cd = System.DateTime.Now; phx.cb = model.patientID.ToString(); db.PatientFamilyHXes.Add(phx); await db.SaveChangesAsync(); } } catch (Exception ex) { return(ThrowError(ex, "AddPatientFamilyHX in PatientFamilyHXController.")); } response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = phx.fhxid, message = "" }); return(response); }
public async Task <HttpResponseMessage> AddPatientAllergy(PatientAllergies_Custom model) { PatientAllergy pallergy = new PatientAllergy(); try { if (model.allergyName == "" || model.allergyName == null || !Regex.IsMatch(model.allergyName.Trim(), "^[0-9a-zA-Z ]+$")) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid allergy name. Only letters and numbers are allowed." }); return(response); } if (model.patientID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid patient ID." }); return(response); } pallergy = db.PatientAllergies.Where(all => all.patientID == model.patientID && all.allergyName.Trim() == model.allergyName.Trim() && all.active == true).FirstOrDefault(); if (pallergy == null) { pallergy = new PatientAllergy(); pallergy.active = true; pallergy.allergyName = model.allergyName; pallergy.severity = model.severity; pallergy.reaction = model.reaction; pallergy.patientID = model.patientID; pallergy.cd = System.DateTime.Now; pallergy.source = "S"; pallergy.reportedDate = System.DateTime.Now; pallergy.cb = pallergy.patientID.ToString(); db.PatientAllergies.Add(pallergy); await db.SaveChangesAsync(); } else { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Allergy already exists." }); response.ReasonPhrase = "Allergy already exists"; return(response); } } catch (Exception ex) { return(ThrowError(ex, "AddPatientAllergy in PatientAllergiesController.")); } response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = pallergy.allergiesID, message = "" }); return(response); }
public async Task <HttpResponseMessage> AddPatientSugery(PatientSurgery_Custom model) { PatientSurgery psurgery = new PatientSurgery(); try { if (model.bodyPart == null || model.bodyPart == "") { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid surgery name." }); return(response); } if (model.patientID == null || model.patientID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid patient id." }); return(response); } psurgery = db.PatientSurgeries.Where(p => p.bodyPart.Trim() == model.bodyPart.Trim() && p.patientID == model.patientID && p.active == true).FirstOrDefault(); if (psurgery != null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Surgery already exists." }); response.ReasonPhrase = "Surgery already exists."; return(response); } if (psurgery == null) { psurgery = new PatientSurgery(); psurgery.active = true; psurgery.bodyPart = model.bodyPart; psurgery.patientID = model.patientID; psurgery.cd = System.DateTime.Now; psurgery.reportedDate = System.DateTime.Now; psurgery.cb = model.patientID.ToString(); db.PatientSurgeries.Add(psurgery); await db.SaveChangesAsync(); } } catch (Exception ex) { return(ThrowError(ex, "AddPatientSurgery in PatientSurgeriesController.")); } response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = psurgery.surgeryID, message = "" }); return(response); }
public async Task <HttpResponseMessage> AddPatientCondition(PatientConditions_Custom model) { Condition condition = new Condition(); try { if (model.conditionName == null || model.conditionName == "" || !Regex.IsMatch(model.conditionName.Trim(), "^[0-9a-zA-Z ]+$")) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid condition name. Only letters and numbers are allowed." }); return(response); } if (model.patientID == null || model.patientID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid patient ID." }); return(response); } condition = db.Conditions.Where(m => m.patientID == model.patientID && m.conditionName == model.conditionName.Trim() && m.active == true).FirstOrDefault(); if (condition == null) { condition = new Condition(); condition.active = true; condition.conditionName = model.conditionName; condition.patientID = model.patientID; condition.cd = System.DateTime.Now; condition.Source = "S"; condition.reportedDate = System.DateTime.Now; condition.cb = model.patientID.ToString(); db.Conditions.Add(condition); await db.SaveChangesAsync(); } else { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Condition name already exists." }); response.ReasonPhrase = "Condition name already exists."; return(response); } } catch (Exception ex) { return(ThrowError(ex, "AddPatientCondition in PatientConditionController.")); } response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = condition.conditionID, message = "" }); return(response); }
public async Task <HttpResponseMessage> AddFavourite(FavouriteDoctorModel model) { FavouriteDoctor favdoc = new FavouriteDoctor(); try { if (model.docID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid doctor ID." }); return(response); } if (model.patID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid patient ID." }); return(response); } favdoc = db.FavouriteDoctors.Where(fav => fav.doctorID == model.docID && fav.patientID == model.patID && fav.active == false).FirstOrDefault(); if (favdoc != null) { favdoc.active = true; favdoc.doctorID = model.docID; favdoc.patientID = model.patID; favdoc.mb = model.patID.ToString(); favdoc.md = System.DateTime.Now; db.Entry(favdoc).State = EntityState.Modified; await db.SaveChangesAsync(); } else { favdoc = new FavouriteDoctor(); favdoc.active = true; favdoc.doctorID = model.docID; favdoc.patientID = model.patID; favdoc.mb = model.patID.ToString(); favdoc.md = System.DateTime.Now; db.FavouriteDoctors.Add(favdoc); await db.SaveChangesAsync(); } } catch (Exception ex) { ThrowError(ex, "AddFavourite in SearchDoctorController."); } response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = favdoc.favID, message = "" }); return(response); }
public async Task <HttpResponseMessage> AddLiveReqLog(LiveReqLogModel model) { LiveReqLog lrlog = new LiveReqLog(); try { if (model.patientID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid patient ID." }); return(response); } if (model.From == "" || model.From == null || !(IsValid(model.From))) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Provide valid email for sender of message." }); return(response); } if (model.doctorID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid doctor ID." }); return(response); } if (model.message == "" || model.message == null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Message text is missing." }); return(response); } lrlog.patientID = model.patientID; lrlog.cd = System.DateTime.Now; lrlog.doctorID = model.doctorID; lrlog.message = model.message; lrlog.From = model.From; lrlog.cb = model.From; db.LiveReqLogs.Add(lrlog); await db.SaveChangesAsync(); response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = lrlog.LiveReqID, message = "" }); return(response); } catch (Exception ex) { return(ThrowError(ex, "AddLiveReqLog in LiveRequestLogController")); } }
public async Task <HttpResponseMessage> AddVCLog(VCLogModel model) { VCLog vclog = new VCLog(); try { if (model.consultID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid consult ID." }); return(response); } if (model.endBy == "" || model.endBy == null || !(IsValid(model.endBy))) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Provide valid email for endBy field." }); return(response); } if (model.logBy == "" || model.logBy == null || !(IsValid(model.logBy))) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Provide valid email for logBy field." }); return(response); } if (model.endReason == "" || model.endReason == null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Provide end reason." }); return(response); } vclog.consultID = model.consultID; vclog.cd = System.DateTime.Now; vclog.endReason = model.endReason; vclog.endBy = model.endBy; vclog.logBy = model.logBy; vclog.duration = model.duration; db.VCLogs.Add(vclog); await db.SaveChangesAsync(); response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = vclog.VCLogID, message = "" }); return(response); } catch (Exception ex) { return(ThrowError(ex, "AddVCLog in VideoConferenceController")); } }
public async Task <HttpResponseMessage> AddPatientLifeStyle(PatientLifeStyle_Custom model) { PatientLifeStyle plifestyle = new PatientLifeStyle(); try { if (model.question == null || model.question == "") { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid question." }); return(response); } if (model.patientID == null || model.patientID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid patient id." }); return(response); } plifestyle = new PatientLifeStyle(); plifestyle.active = true; plifestyle.question = model.question; plifestyle.answer = model.answer; plifestyle.patientID = model.patientID; plifestyle.cd = System.DateTime.Now; plifestyle.cb = model.patientID.ToString(); db.PatientLifeStyles.Add(plifestyle); await db.SaveChangesAsync(); } catch (Exception ex) { return(ThrowError(ex, "AddPatientLifeStyle in PatientLifeStyleController.")); } response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = plifestyle.patientlifestyleID, message = "" }); return(response); }
public async Task <HttpResponseMessage> AddChatMessages(ChatMessageModel model) { ChatLog chatLog = new ChatLog(); try { if (model.consultID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid consult ID." }); return(response); } //if (model.sender == "" || model.sender == null)//|| !(IsValid(model.sender) //{ // response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Provide valid email for sender." }); // return response; //} if (model.reciever == "" || model.reciever == null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Provide valid email for reciever." }); return(response); } if (model.message == "" || model.message == null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Blank message is not allowed." }); return(response); } chatLog.consultID = model.consultID; chatLog.cd = System.DateTime.Now; chatLog.sender = model.sender; chatLog.reciever = model.reciever; chatLog.message = model.message; db.ChatLogs.Add(chatLog); await db.SaveChangesAsync(); response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = chatLog.chatID, message = "" }); return(response); } catch (Exception ex) { return(ThrowError(ex, "AddChatMessages in ChatController")); } }
public async Task <HttpResponseMessage> AddPharmacy(PatientPharmacy_Custom model) { Patient patient = new Patient(); try { if (model.pharmacy == "" || model.pharmacy == null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid pharmacy name. Only letters and numbers are allowed." }); return(response); } if (model.patientID == 0 || model.patientID == null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid patient ID" }); return(response); } patient = db.Patients.Where(m => m.patientID == model.patientID).FirstOrDefault(); if (patient == null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Patient record not found." }); return(response); } patient.pharmacy = model.pharmacy; patient.pharmacyaddress = model.pharmacyaddress; patient.pharmacycitystatezip = model.pharmacycitystatezip; patient.pharmacyid = model.pharmacyid; patient.md = System.DateTime.Now; patient.mb = model.patientID.ToString(); db.Entry(patient).State = EntityState.Modified; await db.SaveChangesAsync(); } catch (Exception ex) { return(ThrowError(ex, "AddPharmacy in PharmacyController.")); } response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = Convert.ToInt64(model.pharmacyid), message = "" }); return(response); }
public ActionResult ApproveDoctor(FormCollection collection) { if (Session["LogedUserID"] != null) { try { long id = Convert.ToInt64(Request.Form["id"].ToString()); var email = Request.Form["email"].ToString(); Doctor doc = db.Doctors.Where(d => d.doctorID == id && d.active == true && d.status == false).FirstOrDefault(); doc.status = true; doc.mb = doc.doctorID.ToString(); doc.md = System.DateTime.Now; db.Entry(doc).State = EntityState.Modified; db.SaveChangesAsync(); //db.sp_ApproveDoctor(Convert.ToInt64(id),Session["LogedUserID"].ToString(), System.DateTime.Now); //db.SaveChanges(); //Send Simple Email var sampleEmailBody = @" <h3>Mail From SwiftKare</h3> <p>Your account has been approved by Swift Kare.</p> <p>You can login now.</p> <p> </p> <p><strong>-Best Regards,<br/>Swift Kare</strong></p> "; var oSimpleEmail = new EmailHelper(email, "SwiftKare Membership", sampleEmailBody); oSimpleEmail.SendMessage(); var reloaddoc = db.SP_SelectDoctorsForApproval(); return(View("DoctorsForApproval", reloaddoc)); //return RedirectToAction("DoctorsForApproval"); } catch (Exception ex) { return(RedirectToAction("DoctorsForApproval")); } } else { return(RedirectToAction("AdminLogin", "Account")); } }
public async Task <HttpResponseMessage> SendMessage(MessageCustomModel model) { try { Message email = new Message(); string fromName = ""; var docsender = (from doc in db.Doctors where doc.email == model.@from select new DoctorModel { firstName = doc.firstName, lastName = doc.lastName }).FirstOrDefault(); var patsender = (from pat in db.Patients where pat.email == model.@from select new PatientModel { firstName = pat.firstName, lastName = pat.lastName }).FirstOrDefault(); if (docsender != null) { fromName = docsender.firstName + " " + docsender.lastName; } if (patsender != null) { fromName = patsender.firstName + " " + patsender.lastName; } if (model.to == "0") { model.to = "*****@*****.**"; } if (model.to == "" || model.to == null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Reciever's email address is invalid." }); return(response); } if (!(IsValid(model.to))) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Reciever's email address is invalid." }); return(response); } if (model.from == null || model.from == "" || !(IsValid(model.from))) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Sender's email address is invalid." }); return(response); } if (model.message == null || model.message == "") { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Empty message is not allowed." }); return(response); } email.cd = System.DateTime.Now; email.senderName = fromName; email.subject = model.subject; email.mesage = model.message; email.from = model.from; email.to = model.to; email.isRead = false; email.status = "1"; email.replyLink = model.replyLink; if (model.msgFile != null) { email.hasAttachment = true; } if (model.msgFile == null) { email.hasAttachment = false; } db.Messages.Add(email); await db.SaveChangesAsync(); if (model.msgFile != null) { foreach (var item in model.msgFile) { MessageFile emailattch = new MessageFile(); emailattch.msgID = email.msgID; emailattch.fileContent = item.fileContent; emailattch.fileName = item.fileName; db.MessageFiles.Add(emailattch); await db.SaveChangesAsync(); } } response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = email.msgID, message = "" }); return(response); } catch (Exception ex) { return(ThrowError(ex, "SendMessage in MessagesController.")); } }
public async Task <IHttpActionResult> PutDoctorTiming(long id, DoctorTimingsModel doctorTimingModel) { var doctorTiming = new DoctorTiming(); var timingsList = GetDoctorTimingByDoctorId(id); var alreadItems = timingsList .Where(o => o.day == doctorTimingModel.day && (o.from == doctorTimingModel.from || o.to == doctorTimingModel.to || ( DateTime.ParseExact(doctorTimingModel.from, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay >= DateTime.ParseExact(o.from, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay && DateTime.ParseExact(doctorTimingModel.from, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay <= DateTime.ParseExact(o.to, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay ) || ( DateTime.ParseExact(doctorTimingModel.to, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay >= DateTime.ParseExact(o.from, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay && DateTime.ParseExact(doctorTimingModel.to, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay <= DateTime.ParseExact(o.to, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay ) || ( DateTime.ParseExact(doctorTimingModel.from, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay <= DateTime.ParseExact(o.from, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay && DateTime.ParseExact(doctorTimingModel.to, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay >= DateTime.ParseExact(o.to, "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay ) )).ToList(); if (alreadItems.Count >= 0) { } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != doctorTimingModel.doctorTimingsID) { return(BadRequest()); } doctorTiming.doctorID = doctorTimingModel.doctorID; doctorTiming.doctorTimingsID = id; doctorTiming.day = doctorTimingModel.day; doctorTiming.active = true; doctorTiming.md = DateTime.Now; doctorTiming.mb = doctorTimingModel.username; DateTime dateTimeFrom = DateTime.ParseExact(doctorTimingModel.from, "hh:mm tt", CultureInfo.InvariantCulture); DateTime dateTimeTo = DateTime.ParseExact(doctorTimingModel.to, "hh:mm tt", CultureInfo.InvariantCulture); doctorTiming.from = dateTimeFrom.TimeOfDay; doctorTiming.to = dateTimeTo.TimeOfDay; db.Entry(doctorTiming).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DoctorTimingExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <DataAccess.CustomModels.UserModel> Register(RegisterApiModel model, HttpRequestMessage request) { var userModel = new DataAccess.CustomModels.UserModel { Email = model.Email, FirstName = model.FirstName, LastName = model.LastName }; if (!request.IsValidClient()) { var resp = new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent("Unauthorized, Client is not valid"), ReasonPhrase = "Bad Request" }; throw new HttpResponseException(resp); } if (model.Role.ToLower() == "patient" || model.Role.ToLower() == "doctor") { try { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { SwiftKareDBEntities db = new SwiftKareDBEntities(); if (model.Role.ToLower() == "patient") { var resultRole = await UserManager.AddToRoleAsync(user.Id, "Patient"); var patient = new Patient { userId = user.Id, lastName = model.LastName, firstName = model.FirstName, email = user.Email, active = true }; db.Patients.Add(patient); await db.SaveChangesAsync(); userModel.Id = patient.patientID; //add the patient } else if (model.Role.ToLower() == "doctor") { var resultRole = await UserManager.AddToRoleAsync(user.Id, "Doctor"); var doctor = new Doctor { userId = user.Id, lastName = model.LastName, firstName = model.FirstName, email = user.Email, active = true, status = false }; db.Doctors.Add(doctor); await db.SaveChangesAsync(); userModel.Id = doctor.doctorID; } else { } } else { userModel.Errors = result.Errors.ToList(); } return(userModel); } catch (Exception) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("An error occurred while posting in api/Account/Register, please try again or contact the administrator."), ReasonPhrase = "Critical Exception" }); } } else { var resp = new HttpResponseMessage(HttpStatusCode.NotImplemented) { Content = new StringContent("Role is undefined"), ReasonPhrase = "Undefined Role" }; throw new HttpResponseException(resp); } }
public async Task <DataAccess.CustomModels.UserModel> UniversalLogin(PatientLoginApiModel model, HttpRequestMessage request) { string[] lines = { "UniversalLogin", new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(model) }; string path = System.IO.Path.Combine(@"C:\ApiLogs\", DateTime.Now.ToString("yyMMddHHmmssff")); // string fullSavePath = Path.Combine(("~/Content/ApiLogs/{0}.txt", DateTime.Now.ToString())); // string fullSavePath = System.Web.HttpContext.Current.Server.MapPath(string.Format("~/Content/{0}.txt", DateTime.Now.ToString())); System.IO.File.WriteAllLines(path, lines); var userModel = new DataAccess.CustomModels.UserModel { Email = model.Email }; if (!request.IsValidClient()) { var resp = new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent("Unauthorized, Client is not valid"), ReasonPhrase = "Bad Request" }; throw new HttpResponseException(resp); } //if (model.Role.ToLower() == "patient" || model.Role.ToLower() == "doctor") //{ try { // var id = headerValues.FirstOrDefault(); // This doen't count login failures towards lockout only two factor authentication // To enable password failures to trigger lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email.Trim(), model.Password.Trim(), false, shouldLockout : false); if (result == SignInStatus.Success) { /* if (model.offset != null) * { * if (model.offset.Equals("330")) model.offset = "-330"; * if (model.offset.Trim().Equals("")) model.offset = "-300"; * } * else model.offset = "-300";*/ var userId = UserManager.FindByName(model.Email.Trim())?.Id; var roleFromDb = UserManager.GetRoles(userId).FirstOrDefault(); SwiftKareDBEntities db = new SwiftKareDBEntities(); if (roleFromDb.ToString().ToLower() == "doctor") { string iOSToken = model.iOSToken; string androidToken = model.andriodToken; //update doctor table with Tokens Doctor doctor = db.Doctors.SingleOrDefault(o => o.userId == userId); if (doctor != null) { if (model.offset != null) { if (model.offset.Trim() != "") { if (doctor.timezoneoffset != model.offset.Replace("+", "")) { model.offset = model.offset.Replace("+", ""); DataAccess.TimeZone tz = db.TimeZones.FirstOrDefault(t => t.zoneOffset == model.offset); if (tz != null) { doctor.timezone = tz.zoneName; doctor.timezoneoffset = tz.zoneOffset; } } } } if (iOSToken.Trim() != "" && iOSToken.Trim().ToLower() != "iostoken") { doctor.iOSToken = iOSToken; } if (androidToken.Trim() != "" && androidToken.Trim().ToLower() != "androidtoken") { doctor.AndroidToken = androidToken; } db.Entry(doctor).State = EntityState.Modified; await db.SaveChangesAsync(); } // var doctor = db.Doctors.SingleOrDefault(o => o.userId == userId); if (doctor != null) { if (doctor.status == null || doctor.status == false) { userModel.Errors = new List <string>(); userModel.Errors.Add("Account review is in progress. You can login after approval."); } else { userModel.Id = doctor.doctorID; userModel.FirstName = doctor.firstName; userModel.LastName = doctor.lastName; userModel.Email = doctor.email; userModel.title = doctor.title; userModel.timeZone = doctor.timezoneoffset;// timezoneoffset userModel.userId = doctor.userId; userModel.role = roleFromDb.ToString(); userModel.iOSToken = doctor.iOSToken; userModel.AndroidToken = doctor.AndroidToken; } } else { userModel.Errors = new List <string>(); userModel.Errors.Add("User does not exist with this role."); } } else if (roleFromDb.ToString().ToLower() == "patient") { string iOSToken = model.iOSToken; string androidToken = model.andriodToken; //update patient table with Tokens Patient patient = db.Patients.SingleOrDefault(o => o.userId == userId); if (model.offset != null) { if (model.offset.Trim() != "") { if (patient.timezoneoffset != model.offset.Replace("+", "")) { model.offset = model.offset.Replace("+", ""); DataAccess.TimeZone tz = db.TimeZones.FirstOrDefault(t => t.zoneOffset == model.offset); if (tz != null) { patient.timezone = tz.zoneName; patient.timezoneoffset = tz.zoneOffset; } } } } if (iOSToken.Trim() != "" && iOSToken.Trim().ToLower() != "iostoken") { patient.iOSToken = iOSToken; } if (androidToken.Trim() != "" && androidToken.Trim().ToLower() != "androidtoken") { patient.AndroidToken = androidToken; } db.Entry(patient).State = EntityState.Modified; await db.SaveChangesAsync(); if (patient != null) { userModel.Id = patient.patientID; userModel.FirstName = patient.firstName; userModel.LastName = patient.lastName; // userModel.userId = patient.userId; userModel.title = patient.title; userModel.timeZone = patient.timezoneoffset; userModel.userId = patient.userId; userModel.role = roleFromDb.ToString(); userModel.iOSToken = patient.iOSToken; userModel.AndroidToken = patient.AndroidToken; userModel.pictureUrl = System.Configuration.ConfigurationManager.AppSettings["profilePictureURL"].ToString(); } else { userModel.Errors = new List <string>(); userModel.Errors.Add("User does not exist with this role."); } } } else if (result == SignInStatus.Failure) { userModel.Errors = new List <string>(); userModel.Errors.Add("Login fail,Incorrect User name or Password."); } else if (result == SignInStatus.LockedOut) { userModel.Errors = new List <string>(); userModel.Errors.Add("Account has been locked"); } else if (result == SignInStatus.RequiresVerification) { userModel.Errors = new List <string>(); userModel.Errors.Add("Account need to verify"); } } catch (Exception ex) { userModel.Errors = new List <string>(); userModel.Errors.Add("Exception Occur:" + ex.Message); //userModel.Errors.Add(model.Email + "," + model.Password + "," + model.offset + "," + model.iOSToken); return(userModel); /* throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) * { * //Content = new StringContent("An error occurred while posting in api/account/login, please try again or contact the administrator."), * Content = new StringContent(ex.Message), * ReasonPhrase = ex.Message * * }); * }*/ } //} //else //{ //var resp = new HttpResponseMessage(HttpStatusCode.NotImplemented) //{ // Content = new StringContent("Role is undefined"), // ReasonPhrase = "Undefined Role" //}; //throw new HttpResponseException(resp); //} if (userModel.Id <= 0 && userModel.Errors == null) { userModel.Errors = new List <string>(); userModel.Errors.Add("Unexpected error from api/login"); } return(userModel); }
public async Task <HttpResponseMessage> AddPatientFiles(FilesCustomModel model) { UserFile patfile = new UserFile(); try { //if (model.FileName == null || model.FileName == "" || !Regex.IsMatch(model.FileName.Trim(), "^[0-9a-zA-Z ]+$")) //{ // response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid file name. Only letters and numbers are allowed." }); // return response; //} if (model.patientID == null || model.patientID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid patient ID." }); return(response); } /* if (model.doctorID == null || model.doctorID == 0) * { * response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid doctor ID." }); * return response; * }*/ if (model.fileContent == null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "File is empty. " }); response.ReasonPhrase = "Blank file is not allowed."; return(response); } if (model.documentType == null || model.documentType == "") { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Please provide document type. " }); return(response); } var retBase64 = model.fileContent.Substring(model.fileContent.IndexOf("base64,") + 7); byte[] bytefilecontent; bytefilecontent = Convert.FromBase64String(retBase64); patfile = db.UserFiles.Where(m => m.FileName == model.FileName.Trim() && m.active == true).FirstOrDefault(); if (patfile == null) { patfile = new UserFile(); patfile.active = true; patfile.FileName = model.FileName; patfile.patientID = model.patientID; patfile.cd = System.DateTime.Now; patfile.md = System.DateTime.Now; //patfile.doctorID = model.doctorID == -1 ? null : model.doctorID; patfile.fileContent = bytefilecontent; patfile.documentType = model.documentType; patfile.cb = model.patientID.ToString(); db.UserFiles.Add(patfile); await db.SaveChangesAsync(); response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = patfile.fileID, message = "" }); return(response); } else { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "File already exists." }); response.ReasonPhrase = "File already exists."; return(response); } } catch (Exception ex) { return(ThrowError(ex, "Unable to upload file.")); } }
public async System.Threading.Tasks.Task <ActionResult> Create(FormCollection collection) { if (Session["LogedUserID"] != null) { ViewBag.successMessage = ""; ViewBag.errorMessage = ""; var id = ""; var firstName = ""; var lastName = ""; var email = ""; var password = ""; var roleID = ""; try { var action = Request.Form["action"].ToString(); if (action == "create") { firstName = Request.Form["firstname"].ToString(); lastName = Request.Form["lastname"].ToString(); email = Request.Form["email"].ToString(); password = Request.Form["password"].ToString(); //roleID = Request.Form["sltRole"].ToString(); var roles = db.AspNetRoles.ToList(); //if (roleID == "") //{ // ViewBag.successMessage = ""; // ViewBag.errorMessage = "Select valid Role"; // var _existingadminList = db.SP_SelectAdmin(); // //var roles = db.Roles // // .Where(a => a.active == true).ToList(); // ViewBag.Roles = roles; // return View(_existingadminList); //} if (!Regex.IsMatch(firstName, @"^[a-zA-Z\s]+$")) { ViewBag.successMessage = ""; ViewBag.errorMessage = "Provide valid First Name"; var _existingadminList = db.SP_SelectAdmin(); //var roles = db.Roles //.Where(a => a.active == true).ToList(); ViewBag.Roles = roles; return(View(_existingadminList)); } if (!Regex.IsMatch(lastName, @"^[a-zA-Z\s]+$")) { ViewBag.successMessage = ""; ViewBag.errorMessage = "Provide valid Last Name"; var _existingadminList = db.SP_SelectAdmin(); //var roles = db.Roles //.Where(a => a.active == true).ToList(); ViewBag.Roles = roles; return(View(_existingadminList)); } Utility util = new Utility(); if (!(util.IsValid(email))) { ViewBag.successMessage = ""; ViewBag.errorMessage = "Provide valid Email Address"; var _existingadminList = db.SP_SelectAdmin(); //var roles = db.Roles //.Where(a => a.active == true).ToList(); ViewBag.Roles = roles; return(View(_existingadminList)); } var checkemail = ( from p in db.AdminUsers where (p.email == email && p.active == true) select p ).FirstOrDefault(); if (checkemail == null) { var user = new ApplicationUser { UserName = email, Email = email, FirstName = firstName, LastName = lastName, }; var result = await UserManager.CreateAsync(user, password); if (result.Succeeded) { db.SP_AddAdmin(firstName, lastName, email, user.Id, Session["LogedUserID"].ToString()); db.SaveChanges(); var userAssignRole = new UserAssignRoleModel(); userAssignRole.UserId = user.Id;//"8466ba63-b903-4d0a-8633-ce399ed1b542";// userAssignRole.Role = "Admin"; var strContent = JsonConvert.SerializeObject(userAssignRole); var response = ApiConsumerHelper.PostData("api/Roles/AssignRole", strContent); dynamic resultAdd = JsonConvert.DeserializeObject(response); ViewBag.successMessage = "Record has been saved successfully"; ViewBag.errorMessage = ""; } else { ViewBag.successMessage = ""; foreach (var error in result.Errors) { ViewBag.errorMessage = error; } var _existingadminList = db.SP_SelectAdmin(); return(View(_existingadminList)); } } else { ViewBag.successMessage = ""; ViewBag.errorMessage = "User with this Email Address already exists"; var _existingadminList = db.SP_SelectAdmin(); //var roles = db.Roles //.Where(a => a.active == true).ToList(); ViewBag.Roles = roles; return(View(_existingadminList)); } } if (action == "edit") { id = Request.Form["id"].ToString(); firstName = Request.Form["firstName"].ToString(); lastName = Request.Form["lastName"].ToString(); email = Request.Form["email"].ToString(); password = Request.Form["password"].ToString(); //roleID = Request.Form["sltRole"].ToString(); var rroles = db.AspNetRoles.ToList(); //if (roleID == "") //{ // ViewBag.successMessage = ""; // ViewBag.errorMessage = "Select valid Role"; // var _existingadminList = db.SP_SelectAdmin(); // //var roles = db.Roles // // .Where(a => a.active == true).ToList(); // ViewBag.Roles = rroles; // return View(_existingadminList); //} if (!Regex.IsMatch(firstName, @"^[a-zA-Z\s]+$")) { ViewBag.successMessage = ""; ViewBag.errorMessage = "Provide valid First Name"; var _existingadminList = db.SP_SelectAdmin(); //var roles = db.Roles // .Where(a => a.active == true).ToList(); ViewBag.Roles = rroles; return(View(_existingadminList)); } if (!Regex.IsMatch(lastName, @"^[a-zA-Z\s]+$")) { ViewBag.successMessage = ""; ViewBag.errorMessage = "Provide valid Last Name"; var _existingadminList = db.SP_SelectAdmin(); // var roles = db.Roles //.Where(a => a.active == true).ToList(); ViewBag.Roles = rroles; return(View(_existingadminList)); } Utility util = new Utility(); if (!(util.IsValid(email))) { ViewBag.successMessage = ""; ViewBag.errorMessage = "Provide valid Email Address"; var _existingadminList = db.SP_SelectAdmin(); // var roles = db.Roles //.Where(a => a.active == true).ToList(); ViewBag.Roles = rroles; return(View(_existingadminList)); } var checkemail = ( from p in db.AspNetUsers where (p.Email == email && p.Id != id) select p ).FirstOrDefault(); if (checkemail == null) { string token = await UserManager.GeneratePasswordResetTokenAsync(id); var result = await UserManager.ResetPasswordAsync(id, token, password); if (result.Succeeded) { AdminUser adminUser = db.AdminUsers.Where(a => a.userId == id).FirstOrDefault(); if (adminUser != null) { //Update AdminUsers table adminUser.lastName = lastName; adminUser.FirstName = firstName; adminUser.email = email; adminUser.mb = Session["LogedUserID"].ToString(); adminUser.md = DateTime.Now; db.AdminUsers.Add(adminUser); db.Entry(adminUser).State = EntityState.Modified; } //Update AspNetUsers table AspNetUser aspnetUser = await db.AspNetUsers.FindAsync(id); if (aspnetUser == null) { ViewBag.successMessage = ""; ViewBag.errorMessage = "Admin user not found."; return(View()); } aspnetUser.LastName = lastName; aspnetUser.FirstName = firstName; aspnetUser.Email = email; db.AspNetUsers.Add(aspnetUser); db.Entry(aspnetUser).State = EntityState.Modified; await db.SaveChangesAsync(); ViewBag.successMessage = "Record has been saved successfully"; ViewBag.errorMessage = ""; } else { ViewBag.successMessage = ""; foreach (var error in result.Errors) { ViewBag.errorMessage = error; } var _existingadminList = db.SP_SelectAdmin(); return(View(_existingadminList)); } } else { ViewBag.successMessage = ""; ViewBag.errorMessage = "User with this Email Address already exists"; var _existingadminList = db.SP_SelectAdmin(); //var roles = db.Roles //.Where(a => a.active == true).ToList(); ViewBag.Roles = rroles; return(View(_existingadminList)); } } if (action == "delete") { id = Request.Form["id"].ToString(); var userid = Request.Form["userid"].ToString(); AdminUser adminUser = db.AdminUsers.Where(a => a.userId == userid).FirstOrDefault(); if (adminUser != null) { //Update AdminUsers table adminUser.active = false; adminUser.mb = Session["LogedUserID"].ToString(); adminUser.md = DateTime.Now; db.Entry(adminUser).State = EntityState.Modified; db.SaveChanges(); ViewBag.successMessage = "Record has been deleted successfully"; ViewBag.errorMessage = ""; } //db.sp_DeleteAdmin(Convert.ToInt64(id), Session["LogedUserID"].ToString(), System.DateTime.Now); //AspNetUser admin = db.AspNetUsers.Find(userid); //db.AspNetUsers.Remove(admin); //db.AspNetUsers.Remove(admin); //db.SaveChanges(); else { ViewBag.successMessage = ""; ViewBag.errorMessage = "Admin user not found."; } } //Send Email// //Send Email// var __existingadminList = db.SP_SelectAdmin(); // var _roles = db.Roles //.Where(a => a.active == true).ToList(); var _roles = db.AspNetRoles.ToList(); ViewBag.Roles = _roles; return(View(__existingadminList)); } catch (Exception ex) { ViewBag.errorMessage = "Error occurred while processing your request."; var _existingadminList = db.SP_SelectAdmin(); var roles = db.AspNetRoles.ToList(); ViewBag.Roles = roles; return(View(_existingadminList)); } } else { return(RedirectToAction("AdminLogin", "Account")); } }