Ejemplo n.º 1
0
        public IHttpActionResult Get(int Id)
        {
            VaccineDTO vaccineDTO = null;

            try
            {
                using (VDEntities entities = new VDEntities())
                {
                    var dbVaccine = entities.Vaccines.Where(c => c.ID == Id).FirstOrDefault();
                    vaccineDTO = Mapper.Map <VaccineDTO>(dbVaccine);
                    if (vaccineDTO != null)
                    {
                        return(Ok(vaccineDTO));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
            }
            catch (Exception e)
            {
                return(BadRequest(GetMessageFromExceptionObject(e)));
            }
        }
Ejemplo n.º 2
0
 public Response <MessageDTO> Post([FromBody] MessageDTO msg)
 {
     try
     {
         using (VDEntities entities = new VDEntities())
         {
             if (!string.IsNullOrEmpty(msg.SMS) && !string.IsNullOrEmpty(msg.MobileNumber))
             {
                 var dbReceiver = entities.Users.Where(x => x.MobileNumber == msg.MobileNumber).FirstOrDefault();
                 if (dbReceiver != null)
                 {
                     var response = UserSMS.SendSMS(dbReceiver.CountryCode, dbReceiver.MobileNumber, "", msg.SMS);
                     UserSMS.addMessageToDB(dbReceiver.MobileNumber, response, msg.SMS, dbReceiver.ID);
                     return(new Response <MessageDTO>(true, null, null));
                 }
                 else
                 {
                     return(new Response <MessageDTO>(false, "The number " + msg.MobileNumber + " does not exist in our records", null));
                 }
             }
             else
             {
                 return(new Response <MessageDTO>(false, "Please fill sms and mobile number text fields", null));
             }
         }
     }
     catch (Exception ex)
     {
         return(new Response <MessageDTO>(false, GetMessageFromExceptionObject(ex), null));
     }
 }
Ejemplo n.º 3
0
 public IHttpActionResult Delete(int Id)
 {
     try
     {
         using (VDEntities entities = new VDEntities())
         {
             var dbVaccine = entities.Vaccines.Where(c => c.ID == Id).FirstOrDefault();
             if (dbVaccine.Brands.Count > 0)
             {
                 return(BadRequest(CANNOT_DELETE_VACCINE_BRAND_ALREADY_EXISTS));
             }
             else if (dbVaccine == null)
             {
                 NotFound();
             }
             entities.Vaccines.Remove(dbVaccine);
             entities.SaveChanges();
             return(BadRequest(RECORD_DELETED));
         }
     }
     catch (Exception e)
     {
         if (e.InnerException.InnerException.Message.Contains(DELETE_CONFLICTED_WITH_REFERENCE_CONSTRAINT))
         {
             return(BadRequest(CANNOT_DELETE_VACCINE_DOSES_ALREADY_EXISTS));
         }
         else
         {
             return(BadRequest(GetMessageFromExceptionObject(e)));
         }
     }
 }
Ejemplo n.º 4
0
 public IHttpActionResult Put(int Id, DoseDTO doseDTO)
 {
     try
     {
         using (VDEntities entities = new VDEntities())
         {
             var dbDose = entities.Doses.Where(c => c.ID == Id).FirstOrDefault();
             if (dbDose != null)
             {
                 dbDose.Name      = doseDTO.Name == null ? dbDose.Name : doseDTO.Name;
                 dbDose.MinAge    = doseDTO.MinAge == 0 ? dbDose.MinAge : doseDTO.MinAge;
                 dbDose.MaxAge    = doseDTO.MaxAge == null ? dbDose.MaxAge : doseDTO.MaxAge;
                 dbDose.MinGap    = doseDTO.MinGap == null ? dbDose.MinGap : doseDTO.MinGap;
                 dbDose.DoseOrder = doseDTO.DoseOrder == 0 ? dbDose.DoseOrder : doseDTO.DoseOrder;
                 entities.SaveChanges();
                 doseDTO = Mapper.Map <DoseDTO>(dbDose);
                 return(Ok(doseDTO));
             }
             return(NotFound());
         }
     }
     catch (Exception e)
     {
         return(BadRequest(GetMessageFromExceptionObject(e)));
     }
 }
        public Response <ClinicDTO> EditClinic(ClinicDTO clinicDTO)
        {
            try
            {
                using (VDEntities entities = new VDEntities())
                {
                    var dbClinic = entities.Clinics.Where(c => c.ID == clinicDTO.ID).FirstOrDefault();
                    if (clinicDTO.IsOnline)
                    {
                        dbClinic.IsOnline = true;
                    }

                    var clinicList = entities.Clinics.Where(x => x.DoctorID == clinicDTO.DoctorID).Where(x => x.ID != clinicDTO.ID).ToList();
                    if (clinicList.Count != 0)
                    {
                        foreach (var clinic in clinicList)
                        {
                            clinic.IsOnline = false;
                            entities.Clinics.Attach(clinic);
                            entities.Entry(clinic).State = EntityState.Modified;
                        }
                    }
                    entities.SaveChanges();
                    clinicDTO.Name = dbClinic.Name;
                    return(new Response <ClinicDTO>(true, null, clinicDTO));
                }
            }
            catch (Exception ex)
            {
                return(new Response <ClinicDTO>(false, ex.Message, null));
            }
        }
Ejemplo n.º 6
0
 public Response <UserDTO> ChangePassword(ChangePasswordRequestDTO user)
 {
     try
     {
         using (VDEntities entities = new VDEntities())
         {
             User userDB = entities.Users.Where(x => x.ID == user.UserID).FirstOrDefault();
             if (userDB == null)
             {
                 return(new Response <UserDTO>(false, "User not found.", null));
             }
             if (!userDB.Password.Equals(user.OldPassword))
             {
                 return(new Response <UserDTO>(false, "Old password doesn't match.", null));
             }
             else
             {
                 userDB.Password = user.NewPassword;
                 entities.SaveChanges();
                 return(new Response <UserDTO>(true, "Password change successfully.", null));
             }
         }
     }
     catch (Exception e)
     {
         return(new Response <UserDTO>(false, GetMessageFromExceptionObject(e), null));
     }
 }
        public Response <ScheduleDTO> AddVacations(ScheduleDTO obj)
        {
            try
            {
                using (VDEntities entities = new VDEntities())
                {
                    foreach (var clinic in obj.Clinics)
                    {
                        var dbSchedules = entities.Schedules.Where(x => x.Child.ClinicID == clinic.ID &&
                                                                   x.Date >= obj.FromDate && x.Date <= obj.ToDate).ToList();

                        foreach (Schedule schedule in dbSchedules)
                        {
                            schedule.Date = obj.ToDate.AddDays(1);
                            entities.SaveChanges();
                        }
                    }

                    return(new Response <ScheduleDTO>(true, "Vacations are considered and appointments are moved to " +
                                                      obj.ToDate.AddDays(1).ToString("dd-MM-yyy") + " date.", null));
                }
            }
            catch (Exception e)
            {
                return(new Response <ScheduleDTO>(false, GetMessageFromExceptionObject(e), null));
            }
        }
        public Response <VaccineDTO> Post(VaccineDTO vaccineDTO)
        {
            try
            {
                using (VDEntities entities = new VDEntities())
                {
                    Vaccine vaccinedb = Mapper.Map <Vaccine>(vaccineDTO);
                    entities.Vaccines.Add(vaccinedb);
                    entities.SaveChanges();
                    vaccineDTO.ID = vaccinedb.ID;
                    //add vaccine in brand
                    Brand dbBrand = new Brand();
                    dbBrand.VaccineID = vaccinedb.ID;
                    dbBrand.Name      = "Local";
                    entities.Brands.Add(dbBrand);
                    entities.SaveChanges();

                    return(new Response <VaccineDTO>(true, null, vaccineDTO));
                }
            }
            catch (Exception e)
            {
                return(new Response <VaccineDTO>(false, GetMessageFromExceptionObject(e), null));
            }
        }
Ejemplo n.º 9
0
 public HttpResponseMessage CheckUniqueMobile(string MobileNumber)
 {
     try
     {
         using (VDEntities entities = new VDEntities())
         {
             User userDB = entities.Users.Where(x => x.MobileNumber == MobileNumber)
                           .Where(u => u.UserType == "DOCTOR").FirstOrDefault();
             if (userDB == null)
             {
                 return(Request.CreateResponse((HttpStatusCode)200));
             }
             else
             {
                 //return BadRequest("Mobile number already exists");
                 //return Content((HttpStatusCode)400, "Mobile number already exists");
                 //return new System.Web.Http.Results.ResponseMessageResult(
                 //    Request.CreateErrorResponse((HttpStatusCode)422, new HttpError("Mobile number already exists")));
                 int HTTPResponse = 400;
                 var response     = Request.CreateResponse((HttpStatusCode)HTTPResponse);
                 response.ReasonPhrase = "Mobile Number already in use";
                 return(response);
             }
         }
     }
     catch (Exception e)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
     }
 }
        public Response <List <ScheduleDTO> > GetVaccineBrands(ScheduleDTO scheduleDto)
        {
            try
            {
                using (VDEntities entities = new VDEntities())
                {
                    var dbSchedule = entities.Schedules.Where(x => x.Date == scheduleDto.Date && x.ChildId == scheduleDto.ChildId).ToList();

                    List <ScheduleDTO> scheduleDTOs = new List <ScheduleDTO>();
                    foreach (var schedule in dbSchedule)
                    {
                        ScheduleDTO     scheduleDTO = new ScheduleDTO();
                        var             dbBrands    = schedule.Dose.Vaccine.Brands.ToList();
                        List <BrandDTO> brandDTOs   = Mapper.Map <List <BrandDTO> >(dbBrands);
                        scheduleDTO.Dose   = Mapper.Map <DoseDTO>(schedule.Dose);
                        scheduleDTO.ID     = schedule.ID;
                        scheduleDTO.Brands = brandDTOs;
                        scheduleDTO.Date   = schedule.Date;
                        scheduleDTO.IsDone = schedule.IsDone;
                        scheduleDTOs.Add(scheduleDTO);
                    }

                    return(new Response <List <ScheduleDTO> >(true, null, scheduleDTOs));
                }
            }
            catch (Exception e)
            {
                return(new Response <List <ScheduleDTO> >(false, GetMessageFromExceptionObject(e), null));
            }
        }
 public Response <IEnumerable <ClinicDTO> > GetAllClinicsOfaDoctor(int id)
 {
     try
     {
         using (VDEntities entities = new VDEntities())
         {
             var doctor = entities.Doctors.FirstOrDefault(c => c.ID == id);
             if (doctor == null)
             {
                 return(new Response <IEnumerable <ClinicDTO> >(false, "Doctor not found", null));
             }
             else
             {
                 var dbClinics = doctor.Clinics.ToList();
                 List <ClinicDTO> clinicDTOs = new List <ClinicDTO>();
                 foreach (var clinic in dbClinics)
                 {
                     ClinicDTO clinicDTO = Mapper.Map <ClinicDTO>(clinic);
                     clinicDTO.childrenCount = clinic.Children.Count();
                     clinicDTOs.Add(clinicDTO);
                 }
                 //var clinicDTOs = Mapper.Map<List<ClinicDTO>>(dbClinics);
                 return(new Response <IEnumerable <ClinicDTO> >(true, null, clinicDTOs));
             }
         }
     }
     catch (Exception e)
     {
         return(new Response <IEnumerable <ClinicDTO> >(false, GetMessageFromExceptionObject(e), null));
     }
 }
 public HttpResponseMessage CheckUniqueEmail(string Email)
 {
     try
     {
         using (VDEntities entities = new VDEntities())
         {
             Doctor doctorDB = entities.Doctors.Where(x => x.Email == Email).FirstOrDefault();
             if (doctorDB == null)
             {
                 return(Request.CreateResponse((HttpStatusCode)200));
             }
             else
             {
                 int HTTPResponse = 400;
                 var response     = Request.CreateResponse((HttpStatusCode)HTTPResponse);
                 response.ReasonPhrase = "Email already in use";
                 return(response);
             }
         }
     }
     catch (Exception e)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
     }
 }
        public Response <DoctorDTO> UpdateUploadedImages(int id)
        {
            try
            {
                VDEntities entities = new VDEntities();
                var        dbDoctor = entities.Doctors.Where(d => d.ID == id).FirstOrDefault();
                if (HttpContext.Current.Request.Files.AllKeys.Any())
                {
                    var httpPostedProfileImage   = HttpContext.Current.Request.Files["ProfileImage"];
                    var httpPostedSignatureImage = HttpContext.Current.Request.Files["SignatureImage"];

                    if (httpPostedProfileImage != null)
                    {
                        var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/UserImages"), httpPostedProfileImage.FileName);
                        httpPostedProfileImage.SaveAs(fileSavePath);
                        dbDoctor.ProfileImage = httpPostedProfileImage.FileName;
                    }
                    if (httpPostedSignatureImage != null)
                    {
                        var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/UserImages"), httpPostedSignatureImage.FileName);
                        httpPostedSignatureImage.SaveAs(fileSavePath);
                        dbDoctor.SignatureImage = httpPostedSignatureImage.FileName;
                    }
                    entities.SaveChanges();
                    return(new Response <DoctorDTO>(true, null, null));
                }
                return(new Response <DoctorDTO>(false, "invalid files in request", null));
            }
            catch (Exception e)
            {
                return(new Response <DoctorDTO>(false, "Image not uploaded. \n" + GetMessageFromExceptionObject(e), null));
            }
        }
        public Response <DoctorDTO> Put(int Id, DoctorDTO doctorDTO)
        {
            try
            {
                using (VDEntities entities = new VDEntities())
                {
                    var dbDoctor = entities.Doctors.Where(c => c.ID == Id).FirstOrDefault();
                    dbDoctor.FirstName   = doctorDTO.FirstName;
                    dbDoctor.LastName    = doctorDTO.LastName;
                    dbDoctor.DisplayName = doctorDTO.DisplayName;
                    dbDoctor.IsApproved  = doctorDTO.IsApproved;
                    dbDoctor.Email       = doctorDTO.Email;
                    dbDoctor.PMDC        = doctorDTO.PMDC;
                    dbDoctor.PhoneNo     = doctorDTO.PhoneNo;
                    dbDoctor.ShowPhone   = doctorDTO.ShowPhone;
                    dbDoctor.ShowMobile  = doctorDTO.ShowMobile;

                    //dbDoctor = Mapper.Map<DoctorDTO, Doctor>(doctorDTO, dbDoctor);
                    //entities.Entry<Doctor>(dbDoctor).State = System.Data.Entity.EntityState.Modified;
                    entities.SaveChanges();
                    return(new Response <DoctorDTO>(true, null, doctorDTO));
                }
            }
            catch (Exception e)
            {
                return(new Response <DoctorDTO>(false, GetMessageFromExceptionObject(e), null));
            }
        }
 public Response <string> Delete(int Id)
 {
     try
     {
         using (VDEntities entities = new VDEntities())
         {
             var dbDoctor = entities.Doctors.Where(c => c.ID == Id).FirstOrDefault();
             entities.Doctors.Remove(dbDoctor);
             entities.SaveChanges();
             return(new Response <string>(true, null, "record deleted"));
         }
     }
     catch (Exception ex)
     {
         {
             if (ex.InnerException.InnerException.Message.Contains("The DELETE statement conflicted with the REFERENCE constraint"))
             {
                 return(new Response <string>(false, "Cannot delete child because it schedule exits. Delete the child schedule first.", null));
             }
             else
             {
                 return(new Response <string>(false, GetMessageFromExceptionObject(ex), null));
             }
         }
     }
 }
Ejemplo n.º 16
0
        public Response <List <BrandInventoryDTO> > Get(int Id)
        {
            try
            {
                using (VDEntities entities = new VDEntities())
                {
                    List <BrandInventory> vaccineInventoryDBs = entities.BrandInventories.Include("Brand").Include("Doctor").Where(x => x.DoctorID == Id).ToList();
                    if (vaccineInventoryDBs == null || vaccineInventoryDBs.Count() == 0)
                    {
                        return(new Response <List <BrandInventoryDTO> >(false, "brand inventory not found", null));
                    }

                    List <BrandInventoryDTO> VaccineInventoryDTOs = Mapper.Map <List <BrandInventoryDTO> >(vaccineInventoryDBs);
                    foreach (BrandInventoryDTO brandInventoryDTO in VaccineInventoryDTOs)
                    {
                        brandInventoryDTO.VaccineName = entities.Brands.Where(x => x.ID == brandInventoryDTO.BrandID).FirstOrDefault().Vaccine.Name;
                    }
                    return(new Response <List <BrandInventoryDTO> >(true, null, VaccineInventoryDTOs));
                }
            }
            catch (Exception e)
            {
                return(new Response <List <BrandInventoryDTO> >(false, GetMessageFromExceptionObject(e), null));
            }
        }
        public Response <ScheduleDTO> Update(ScheduleDTO scheduleDTO)
        {
            try
            {
                using (VDEntities entities = new VDEntities())
                {
                    var dbSchedule       = entities.Schedules.Where(c => c.ID == scheduleDTO.ID).FirstOrDefault();
                    var dbBrandInventory = entities.BrandInventories.Where(b => b.BrandID == scheduleDTO.BrandId &&
                                                                           b.DoctorID == scheduleDTO.DoctorID).FirstOrDefault();
                    if (dbBrandInventory != null && dbBrandInventory.Count > 0)
                    {
                        if (scheduleDTO.GivenDate.Date == DateTime.UtcNow.AddHours(5).Date)
                        {
                            dbBrandInventory.Count--;
                        }
                    }
                    dbSchedule.BrandId   = scheduleDTO.BrandId;
                    dbSchedule.Weight    = scheduleDTO.Weight;
                    dbSchedule.Height    = scheduleDTO.Height;
                    dbSchedule.Circle    = scheduleDTO.Circle;
                    dbSchedule.IsDone    = scheduleDTO.IsDone;
                    dbSchedule.GivenDate = scheduleDTO.GivenDate;

                    ChangeDueDatesOfInjectedSchedule(scheduleDTO, entities, dbSchedule);
                    entities.SaveChanges();
                    return(new Response <ScheduleDTO>(true, "schedule updated successfully.", null));
                }
            }
            catch (Exception e)
            {
                return(new Response <ScheduleDTO>(false, GetMessageFromExceptionObject(e), null));
            }
        }
        public Response <ClinicDTO> Put(int Id, ClinicDTO clinicDTO)
        {
            try
            {
                TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
                clinicDTO.Name = textInfo.ToTitleCase(clinicDTO.Name);
                using (VDEntities entities = new VDEntities())
                {
                    var dbClinic = entities.Clinics.Where(c => c.ID == Id).FirstOrDefault();
                    clinicDTO.IsOnline       = false;
                    dbClinic.Name            = clinicDTO.Name;
                    dbClinic.ConsultationFee = clinicDTO.ConsultationFee;
                    dbClinic.StartTime       = clinicDTO.StartTime;
                    dbClinic.EndTime         = clinicDTO.EndTime;
                    dbClinic.PhoneNumber     = clinicDTO.PhoneNumber;
                    dbClinic.OffDays         = clinicDTO.OffDays;
                    dbClinic.Lat             = clinicDTO.Lat;
                    dbClinic.Long            = clinicDTO.Long;
                    dbClinic.Address         = clinicDTO.Address;


                    entities.SaveChanges();
                    return(new Response <ClinicDTO>(true, null, clinicDTO));
                }
            }
            catch (Exception e)
            {
                return(new Response <ClinicDTO>(false, GetMessageFromExceptionObject(e), null));
            }
        }
 public Response <string> Delete(int Id)
 {
     try
     {
         using (VDEntities entities = new VDEntities())
         {
             var dbVaccine = entities.Vaccines.Where(c => c.ID == Id).FirstOrDefault();
             if (dbVaccine.Brands.Count > 0)
             {
                 return(new Response <string>(false, "Cannot delete vaccine because it's brands exists. Delete the brands first", null));
             }
             entities.Vaccines.Remove(dbVaccine);
             entities.SaveChanges();
             return(new Response <string>(true, null, "record deleted"));
         }
     }
     catch (Exception ex)
     {
         if (ex.InnerException.InnerException.Message.Contains("The DELETE statement conflicted with the REFERENCE constraint"))
         {
             return(new Response <string>(false, "Cannot delete vaccine because it's doses exists. Delete the doses first.", null));
         }
         else
         {
             return(new Response <string>(false, GetMessageFromExceptionObject(ex), null));
         }
     }
 }
        public Response <ScheduleDTO> BulkReschedule(ScheduleDTO scheduleDTO, [FromUri] bool ignoreMaxAgeRule = false, [FromUri] bool ignoreMinAgeFromDOB = false, [FromUri] bool ignoreMinGapFromPreviousDose = false)
        {
            try
            {
                using (VDEntities entities = new VDEntities())
                {
                    var dbSchedule = entities.Schedules.Where(x => x.ID == scheduleDTO.ID).FirstOrDefault();

                    var dbSchedules = entities.Schedules.Where(x => x.Date == dbSchedule.Date &&
                                                               x.ChildId == dbSchedule.ChildId &&
                                                               x.IsDone == false
                                                               ).ToList();

                    foreach (var schedule in dbSchedules)
                    {
                        ChangeDueDatesOfSchedule(scheduleDTO, entities, schedule, "bulk", ignoreMaxAgeRule, ignoreMinAgeFromDOB, ignoreMinGapFromPreviousDose);
                    }

                    return(new Response <ScheduleDTO>(true, "schedule updated successfully.", null));
                }
            }
            catch (Exception e)
            {
                return(new Response <ScheduleDTO>(false, GetMessageFromExceptionObject(e), null));
            }
        }
        public Response <IEnumerable <ScheduleDTO> > SendSMSAlertToParent(int GapDays, int OnlineClinicId)
        {
            try
            {
                using (VDEntities entities = new VDEntities())
                {
                    List <Schedule> Schedules  = GetAlertData(GapDays, OnlineClinicId, entities);
                    var             dbChildren = Schedules.Select(x => x.Child).Distinct().ToList();
                    foreach (var child in dbChildren)
                    {
                        var      dbSchedules  = Schedules.Where(x => x.ChildId == child.ID).ToList();
                        var      doseName     = "";
                        DateTime scheduleDate = new DateTime();
                        foreach (var schedule in dbSchedules)
                        {
                            doseName    += schedule.Dose.Name + ", ";
                            scheduleDate = schedule.Date;
                        }
                        UserSMS.ParentSMSAlert(doseName, scheduleDate, child);
                    }

                    List <ScheduleDTO> scheduleDtos = Mapper.Map <List <ScheduleDTO> >(Schedules);
                    return(new Response <IEnumerable <ScheduleDTO> >(true, null, scheduleDtos));
                }
            }
            catch (Exception ex)
            {
                return(new Response <IEnumerable <ScheduleDTO> >(false, GetMessageFromExceptionObject(ex), null));
            }
        }
Ejemplo n.º 22
0
 public IHttpActionResult Delete(int Id)
 {
     try
     {
         using (VDEntities entities = new VDEntities())
         {
             var dbDose = entities.Doses.Where(c => c.ID == Id).FirstOrDefault();
             if (dbDose != null)
             {
                 entities.Doses.Remove(dbDose);
                 entities.SaveChanges();
                 return(Ok(RECORD_DELETED));
             }
             return(NotFound());
         }
     }
     catch (Exception ex)
     {
         if (ex.InnerException.InnerException.Message.Contains(DELETE_CONFLICTED_WITH_REFERENCE_CONSTRAINT))
         {
             return(BadRequest("Cannot delete child because it schedule exits. Delete the child schedule first."));
         }
         else
         {
             return(BadRequest(GetMessageFromExceptionObject(ex)));
         }
     }
 }
 public IHttpActionResult Delete(int Id)
 {
     try
     {
         using (VDEntities entities = new VDEntities())
         {
             var dbVaccineBrand = entities.Brands.Where(c => c.ID == Id).FirstOrDefault();
             if (dbVaccineBrand != null)
             {
                 entities.Brands.Remove(dbVaccineBrand);
                 entities.SaveChanges();
                 return(Ok(RECORD_DELETED));
             }
             return(NotFound());
         }
     }
     catch (Exception ex)
     {
         if (ex.InnerException.InnerException.Message.Contains(DELETE_CONFLICTED_WITH_REFERENCE_CONSTRAINT))
         {
             return(Ok("Cannot delete brand because it is used in Child Schedule, Inventory or Invoice."));
         }
         else
         {
             return(Ok(GetMessageFromExceptionObject(ex)));
         }
     }
 }
 public Response <IEnumerable <ChildDTO> > GetAllChildsOfaDoctor(int id, int pageSize, int currentPage, [FromUri] string searchKeyword = "")
 {
     try
     {
         using (VDEntities entities = new VDEntities())
         {
             var doctor = entities.Doctors.FirstOrDefault(c => c.UserID == id);
             if (doctor == null)
             {
                 return(new Response <IEnumerable <ChildDTO> >(false, "Doctor not found", null));
             }
             else
             {
                 List <ChildDTO> childDTOs     = new List <ChildDTO>();
                 var             doctorClinics = doctor.Clinics;
                 foreach (var clinic in doctorClinics)
                 {
                     if (!String.IsNullOrEmpty(searchKeyword))
                     {
                         if (searchKeyword.StartsWith("+"))
                         {
                             searchKeyword = searchKeyword.Substring(1);
                         }
                         if (searchKeyword.StartsWith("0"))
                         {
                             searchKeyword = searchKeyword.Substring(1);
                         }
                         if (searchKeyword.StartsWith("00"))
                         {
                             searchKeyword = searchKeyword.Substring(2);
                         }
                         if (searchKeyword.StartsWith("92"))
                         {
                             searchKeyword = searchKeyword.Substring(2);
                         }
                         childDTOs.AddRange(Mapper.Map <List <ChildDTO> >(clinic.Children.Where(x => x.Name.ToLower()
                                                                                                .Contains(searchKeyword.ToLower()) || x.FatherName.ToLower().Contains(searchKeyword.ToLower()) ||
                                                                                                x.User.MobileNumber.Contains(searchKeyword.ToLower())).ToList <Child>()));
                     }
                     else
                     {
                         childDTOs.AddRange(Mapper.Map <List <ChildDTO> >(clinic.Children.ToList <Child>().Skip(pageSize * currentPage).Take(pageSize)));
                     }
                 }
                 foreach (var item in childDTOs)
                 {
                     var dbChild = entities.Children.Where(x => x.ID == item.ID).FirstOrDefault();
                     item.MobileNumber = dbChild.User.CountryCode + dbChild.User.MobileNumber;
                 }
                 return(new Response <IEnumerable <ChildDTO> >(true, null, childDTOs.OrderByDescending(x => x.ID).ToList()));
             }
         }
     }
     catch (Exception e)
     {
         return(new Response <IEnumerable <ChildDTO> >(false, GetMessageFromExceptionObject(e), null));
     }
 }
Ejemplo n.º 25
0
 public static void minusDoctorSMSCount(Doctor doctor)
 {
     using (VDEntities entities = new VDEntities())
     {
         Doctor dbDoctor = entities.Doctors.Where(x => x.ID == doctor.ID).FirstOrDefault();
         dbDoctor.SMSLimit--;
         entities.SaveChanges();
     }
 }
Ejemplo n.º 26
0
        public Response <UserDTO> ForgotPassword(UserDTO userDTO)
        {
            try
            {
                using (VDEntities entities = new VDEntities())
                {
                    var dbUser = entities.Users.Where(x => x.MobileNumber == userDTO.MobileNumber)
                                 .Where(x => x.CountryCode == userDTO.CountryCode)
                                 .Where(ut => ut.UserType == userDTO.UserType).FirstOrDefault();

                    if (dbUser == null)
                    {
                        return(new Response <UserDTO>(false, "Invalid Mobile Number", null));
                    }

                    if (dbUser.UserType.Equals("DOCTOR"))
                    {
                        var doctorDb = entities.Doctors.Where(x => x.UserID == dbUser.ID).FirstOrDefault();
                        if (doctorDb == null)
                        {
                            return(new Response <UserDTO>(false, "Invalid Mobile Number", null));
                        }
                        else
                        {
                            UserEmail.DoctorForgotPassword(doctorDb);
                            UserSMS.DoctorForgotPasswordSMS(doctorDb);
                            return(new Response <UserDTO>(true, "your password has been sent to your mobile number and email address", null));
                        }
                    }
                    else if (dbUser.UserType.Equals("PARENT"))
                    {
                        var childDB = entities.Children.Where(x => x.UserID == dbUser.ID).FirstOrDefault();
                        if (childDB == null)
                        {
                            return(new Response <UserDTO>(false, "Invalid Mobile Number", null));
                        }
                        else
                        {
                            UserEmail.ParentForgotPassword(childDB);
                            UserSMS.ParentForgotPasswordSMS(childDB);
                            return(new Response <UserDTO>(true, "your password has been sent to your mobile number and email address", null));
                        }
                    }
                    else
                    {
                        return(new Response <UserDTO>(false, "Please contact with admin", null));
                    }
                }
            }
            catch (Exception e)
            {
                return(new Response <UserDTO>(false, GetMessageFromExceptionObject(e), null));
            }
        }
        public Response <DoctorDTO> Post(DoctorDTO doctorDTO)
        {
            try
            {
                TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
                doctorDTO.FirstName   = textInfo.ToTitleCase(doctorDTO.FirstName);
                doctorDTO.LastName    = textInfo.ToTitleCase(doctorDTO.LastName);
                doctorDTO.DisplayName = textInfo.ToTitleCase(doctorDTO.DisplayName);
                using (VDEntities entities = new VDEntities())
                {
                    // 1- send email to doctor
                    UserEmail.DoctorEmail(doctorDTO);

                    // 2- save User first
                    User userDB = new User();
                    userDB.MobileNumber = doctorDTO.MobileNumber;
                    userDB.Password     = doctorDTO.Password;
                    userDB.CountryCode  = doctorDTO.CountryCode;
                    userDB.UserType     = "DOCTOR";
                    entities.Users.Add(userDB);
                    entities.SaveChanges();

                    // 2- save Doctor
                    Doctor doctorDB = Mapper.Map <Doctor>(doctorDTO);
                    doctorDB.ValidUpto = null;
                    doctorDB.UserID    = userDB.ID;
                    entities.Doctors.Add(doctorDB);
                    entities.SaveChanges();
                    doctorDTO.ID = doctorDB.ID;

                    //generate SMS and save it to the db
                    UserSMS.DoctorSMS(doctorDTO);

                    // 4- check if clinicDto exsist; then save clinic as well
                    if (doctorDTO.ClinicDTO != null && !String.IsNullOrEmpty(doctorDTO.ClinicDTO.Name))
                    {
                        doctorDTO.ClinicDTO.Name = textInfo.ToTitleCase(doctorDTO.ClinicDTO.Name);

                        doctorDTO.ClinicDTO.DoctorID = doctorDB.ID;

                        Clinic clinicDB = Mapper.Map <Clinic>(doctorDTO.ClinicDTO);
                        entities.Clinics.Add(clinicDB);
                        entities.SaveChanges();

                        doctorDTO.ClinicDTO.ID = clinicDB.ID;
                    }
                }
                return(new Response <DoctorDTO>(true, null, doctorDTO));
            }
            catch (Exception ex)
            {
                return(new Response <DoctorDTO>(false, GetMessageFromExceptionObject(ex), null));
            }
        }
Ejemplo n.º 28
0
        public Response <List <MessageDTO> > Get([FromUri] string mobileNumber = "", [FromUri] string fromDate = "", [FromUri] string toDate = "")
        {
            try
            {
                using (VDEntities entities = new VDEntities())
                {
                    List <Message> dbMessages = new List <Message>();
                    var            prevDays   = DateTime.Now.AddDays(-10);
                    if (!string.IsNullOrEmpty(mobileNumber) || !string.IsNullOrEmpty(fromDate) || !string.IsNullOrEmpty(toDate))
                    {
                        var dbUser = entities.Users.Where(x => x.MobileNumber == mobileNumber && x.UserType == "DOCTOR").FirstOrDefault();
                        if (dbUser == null)
                        {
                            return(new Response <List <MessageDTO> >(false, "No records found", null));
                        }
                        if (fromDate != null && toDate == null)
                        {
                            DateTime FromDate = DateTime.ParseExact(fromDate, "dd-MM-yyyy", null);
                            dbMessages = entities.Messages.Where(m => m.UserID == dbUser.ID && m.Created >= FromDate).ToList();
                        }
                        if (toDate != null && fromDate == null)
                        {
                            DateTime ToDate = DateTime.ParseExact(toDate, "dd-MM-yyyy", null);
                            dbMessages = entities.Messages.Where(m => m.UserID == dbUser.ID &&
                                                                 m.Created <= ToDate).ToList();
                        }
                        if (toDate != null && fromDate != null)
                        {
                            DateTime FromDate = DateTime.ParseExact(fromDate, "dd-MM-yyyy", null);
                            DateTime ToDate   = DateTime.ParseExact(toDate, "dd-MM-yyyy", null);

                            dbMessages = entities.Messages.Where(m => m.UserID == dbUser.ID && m.Created >= FromDate &&
                                                                 m.Created <= ToDate).ToList();
                        }
                        if (toDate == null && fromDate == null)
                        {
                            dbMessages = entities.Messages.Where(m => m.UserID == dbUser.ID && m.Created > prevDays).ToList();
                        }
                    }
                    else
                    {
                        dbMessages = entities.Messages.Where(m => m.Created > prevDays).ToList();
                    }


                    var messageDTOs = Mapper.Map <List <MessageDTO> >(dbMessages.OrderByDescending(x => x.Created));
                    return(new Response <List <MessageDTO> >(true, null, messageDTOs));
                }
            }
            catch (Exception ex)
            {
                return(new Response <List <MessageDTO> >(false, GetMessageFromExceptionObject(ex), null));
            }
        }
        public Response <IEnumerable <ScheduleDTO> > SendSMSAlertToOneChild(int GapDays, int childId)
        {
            try
            {
                using (VDEntities entities = new VDEntities())
                {
                    IEnumerable <Schedule> Schedules = new List <Schedule>();
                    DateTime AddedDateTime           = DateTime.UtcNow.AddHours(5).AddDays(GapDays);
                    DateTime pakistanDate            = DateTime.UtcNow.AddHours(5).Date;
                    if (GapDays == 0)
                    {
                        Schedules = entities.Schedules.Include("Child").Include("Dose")
                                    .Where(sc => sc.ChildId == childId)
                                    .Where(sc => sc.Date == pakistanDate)
                                    .Where(sc => sc.IsDone == false)
                                    .OrderBy(x => x.Child.ID).ThenBy(y => y.Date).ToList <Schedule>();
                    }
                    if (GapDays > 0)
                    {
                        Schedules = entities.Schedules.Include("Child").Include("Dose")
                                    .Where(sc => sc.ChildId == childId)
                                    .Where(sc => sc.IsDone == false)
                                    .Where(sc => sc.Date >= pakistanDate && sc.Date <= AddedDateTime)
                                    .OrderBy(x => x.Child.ID).ThenBy(y => y.Date).ToList <Schedule>();
                    }
                    if (GapDays < 0)
                    {
                        Schedules = entities.Schedules.Include("Child").Include("Dose")
                                    .Where(sc => sc.ChildId == childId)
                                    .Where(sc => sc.IsDone == false)
                                    .Where(sc => sc.Date <= pakistanDate && sc.Date >= AddedDateTime)
                                    .OrderBy(x => x.Child.ID).ThenBy(y => y.Date).ToList <Schedule>();
                    }

                    var      doseName     = "";
                    DateTime scheduleDate = new DateTime();
                    var      dbChild      = entities.Children.Where(x => x.ID == childId).FirstOrDefault();
                    foreach (var schedule in Schedules)
                    {
                        doseName    += schedule.Dose.Name.Trim() + ", ";
                        scheduleDate = schedule.Date;
                    }
                    UserSMS.ParentSMSAlert(doseName, scheduleDate, dbChild);

                    List <ScheduleDTO> scheduleDtos = Mapper.Map <List <ScheduleDTO> >(Schedules);
                    return(new Response <IEnumerable <ScheduleDTO> >(true, null, scheduleDtos));
                }
            }
            catch (Exception ex)
            {
                return(new Response <IEnumerable <ScheduleDTO> >(false, GetMessageFromExceptionObject(ex), null));
            }
        }
        private void ChangeDueDatesOfInjectedSchedule(ScheduleDTO scheduleDTO, VDEntities entities, Schedule dbSchedule)
        {
            var daysDifference = Convert.ToInt32((scheduleDTO.GivenDate.Date - dbSchedule.Date.Date).TotalDays);

            var AllDoses = dbSchedule.Dose.Vaccine.Doses;

            AllDoses = AllDoses.Where(x => x.DoseOrder > dbSchedule.Dose.DoseOrder).ToList();
            foreach (var d in AllDoses)
            {
                var TargetSchedule = entities.Schedules.Where(x => x.ChildId == dbSchedule.ChildId && x.DoseId == d.ID).FirstOrDefault();
                TargetSchedule.Date = calculateDate(TargetSchedule.Date, daysDifference); //TargetSchedule.Date.AddDays(daysDifference);
            }
        }