Пример #1
0
        public ActionResult AddPharmacist(int PharmacyCode, string FirstName, string LastName, string Email, string Phone, bool IsAdmin = false, bool IsActive = false)
        {
            using (var service = new PharmacistService())
            {
                Phone = Regex.Replace(Phone, @"[^A-Za-z0-9]+", "");
                if (Phone.Length == 10)
                {
                    Phone = "1" + Phone;
                }
                Pharmacist p = service.GetWhere(PharmacistService.EmailCol == Email).FirstOrDefault();
                if (p == null)
                {
                    p = new Pharmacist(FirstName, LastName, Email, Phone, new byte[] { 0 }, new byte[] { 0 });
                    service.Create(p);
                }


                Pharmacy pharm;
                using (var pharmservice = new PharmacyService())
                {
                    pharm = pharmservice.Get(PharmacyCode);
                }
                using (var jobservice = new JobService())
                {
                    Job j = new Job(pharm, p, IsActive, IsAdmin);
                    jobservice.Create(j);
                }
            }
            using (var service = new EmailService())
            {
                service.SendEmail(Email, newAccountEmailSubject, newAccountEmailBody);
            }
            return(RedirectToAction("SinglePharmacy", new RouteValueDictionary(
                                        new { controller = "SystemAdmin", action = "SinglePharmacy", Id = PharmacyCode })));
        }
Пример #2
0
        public ActionResult UpdateDatabase(string file1)
        {
            // convert string to stream
            byte[] byteArray = Encoding.UTF8.GetBytes(file1); //this one
            //byte[] byteArray = Encoding.ASCII.GetBytes(file);
            MemoryStream stream = new MemoryStream(byteArray);

            //Upload CSV here
            try
            {
                InitDatabaseService init = new InitDatabaseService();
                //init.Reset();
                //this is bad, we need to check for duplicates, not drop the tables
                Pharmacy pharm = User.getPharmacy();
                init.LoadFromMemoryStream(stream, pharm);
                using (var PharmacistService = new PharmacistService())
                    using (var service = new PharmacyService())
                    {
                        pharm.LastUploaded = DateTime.Now.ToUniversalTime();
                        //pharm.LastUploader = PharmacistService.Get(User.Code);
                        service.Update(pharm);
                    }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(Json(ex));
            }

            return(null);
        }
        public ActionResult AddPharmacist(string FirstName, string LastName, string Email, string Phone, bool IsActive = false, bool IsAdmin = false)
        {
            Phone = Regex.Replace(Phone, @"[^A-Za-z0-9]+", "");
            if (Phone.Length == 10)
            {
                Phone = "1" + Phone;
            }
            using (var service = new PharmacistService())
            {
                Pharmacist p = service.GetWhere(PharmacistService.EmailCol == Email).FirstOrDefault();
                if (p == null)
                {
                    new Pharmacist(FirstName, LastName, Email, Phone, new byte[] { 0 }, new byte[] { 0 });
                    service.Create(p);
                }

                Pharmacy pharm;
                using (var pharmservice = new PharmacyService())
                {
                    pharm = pharmservice.Get(User.getPharmacy().Code);
                }

                using (var jobservice = new JobService())
                {
                    //these get the value, not the checked value
                    Job j = new Job(pharm, p, IsActive, IsAdmin);
                    jobservice.Create(j);
                }

                return(RedirectToAction("Pharmacy", new RouteValueDictionary(
                                            new { controller = "ManagePharmacist", action = "Pharmacy", Id = User.Pharmacy.Code })));
            }
        }
Пример #4
0
 public ActionResult PharmacySelect(int pharmacy)
 {
     User.setPharmacy(pharmacy);
     if (pharmacy > -1)
     {
         using (var service = new PharmacistService())
         {
             var pharmacist           = service.GetWhere(PharmacistService.EmailCol == User.Email).FirstOrDefault();
             var serializedPharmacist = new PPOKPrincipalSerializeModel(pharmacist, pharmacy);
             //serializedPharmacist.Pharmacy = User.Pharmacy;
             makeAuthTicket(serializedPharmacist);
         }
         return(RedirectToAction("Index", "LandingPage"));
     }
     else
     {
         using (var service = new SystemAdminService())
         {
             var admin           = service.GetWhere(SystemAdminService.EmailCol == User.Email).FirstOrDefault();
             var serializedAdmin = new PPOKPrincipalSerializeModel(admin);
             serializedAdmin.Pharmacy = User.Pharmacy;
             makeAuthTicket(serializedAdmin);
         }
         return(RedirectToAction("Index", "SystemAdmin"));
     }
 }
        public ActionResult EditPharmacist(int Code, int PharmacyCode, string FirstName, string LastName, string Email, string Phone, bool IsActive = false, bool IsAdmin = false)
        {
            Phone = Regex.Replace(Phone, @"[^A-Za-z0-9]+", "");
            if (Phone.Length == 10)
            {
                Phone = "1" + Phone;
            }
            using (var service = new PharmacistService())
            {
                Pharmacist p = service.Get(Code);
                if (p != null)
                {
                    p.FirstName = FirstName;
                    p.LastName  = LastName;
                    p.Phone     = Phone;
                    p.Email     = Email;
                    service.Update(p);

                    using (var jobservice = new JobService())
                    {
                        //these get the value, not the checked value
                        var job = jobservice.GetWhere(JobService.PharmacistCodeCol == p.Code & JobService.PharmacyCodeCol == PharmacyCode).FirstOrDefault();
                        job.IsActive = IsActive;
                        job.IsAdmin  = IsAdmin;
                        jobservice.Update(job);
                    }
                }

                return(RedirectToAction("Pharmacy", new RouteValueDictionary(
                                            new { controller = "ManagePharmacist", action = "Pharmacy" })));
            }
        }
Пример #6
0
 public static Pharmacist SendPharmacistToken(string email, string token)
 {
     using (var service = new PharmacistService())
     {
         var pharmacist = service.GetWhere(PharmacistService.EmailCol == email).FirstOrDefault();
         if (pharmacist != null)
         {
             using (var tokenService = new PharmacistTokenService())
             {
                 var storedToken = tokenService.GetWhere(PharmacistTokenService.PharmacistCodeCol == pharmacist.Code).FirstOrDefault();
                 if (storedToken == null)
                 {
                     tokenService.Create(new PharmacistToken(pharmacist, token));
                 }
                 else
                 {
                     storedToken.Token   = token;
                     storedToken.Expires = DateTime.Now.ToUniversalTime().AddHours(Config.TokenDuration);
                     tokenService.Update(storedToken);
                 }
             }
             AddSystemAdminToken(email, token);
             TwilioService.SendSMSMessage(pharmacist.Phone, "Please enter this token to login: " + token);
         }
         return(pharmacist);
     }
 }
Пример #7
0
        public ActionResult EditPharmacist(int PharmacistCode, int PharmacyCode, string FirstName, string LastName, string Email, string Phone, bool IsAdmin = false, bool IsActive = false)
        {
            Phone = Regex.Replace(Phone, @"[^A-Za-z0-9]+", "");
            if (Phone.Length == 10)
            {
                Phone = "1" + Phone;
            }
            using (var service = new PharmacistService())
            {
                Pharmacist p = service.Get(PharmacistCode);
                if (p != null)
                {
                    p.FirstName = FirstName;
                    p.LastName  = LastName;
                    p.Phone     = Phone;
                    p.Email     = Email;
                    var temp1 = p.AllJobs.Where(x => x.Pharmacy.Code == PharmacyCode).FirstOrDefault();
                    using (var serviceJob = new JobService())
                    {
                        var j = serviceJob.GetWhere(JobService.CodeCol == temp1.Code).FirstOrDefault();
                        j.IsActive = IsActive;
                        j.IsAdmin  = IsAdmin;
                        serviceJob.Update(j);
                    }

                    service.Update(p);
                }
                return(RedirectToAction("SinglePharmacy", new RouteValueDictionary(
                                            new { controller = "SystemAdmin", action = "SinglePharmacy", Id = PharmacyCode })));
            }
        }
Пример #8
0
 public LoginModel(string email)
 {
     pharmacyList = new List <Pharmacy>();
     using (var service = new PharmacistService())
     {
         var pharmacist = service.GetWhere(PharmacistService.EmailCol == email).FirstOrDefault();
         if (pharmacist != null)
         {
             var jobs = pharmacist.Jobs;
             foreach (var job in jobs)
             {
                 var pharmacy = job.Pharmacy;
                 pharmacyList.Add(job.Pharmacy);
             }
         }
     }
     using (var service = new SystemAdminService())
     {
         var admin = service.GetWhere(SystemAdminService.EmailCol == email).FirstOrDefault();
         if (admin != null)
         {
             pharmacyList.Add(new Pharmacy(-1, "System Admin", "000-000-0000", "no address"));
         }
     }
 }
Пример #9
0
 public JsonResult GetSinglePharmacist(int id, int PharmacyId)
 {
     using (var service = new PharmacistService())
     {
         var result = service.Get(id);
         return(Json(new PharmacistModel(result, PharmacyId)));
     }
 }
Пример #10
0
 public static byte[] HashUserText(Pharmacist pharmacist, string text)
 {
     using (var service = new PharmacistService())
     {
         var salt = service.Get(pharmacist.Code).PasswordSalt;
         return(GenerateSaltedHash(Encoding.ASCII.GetBytes(text.ToLower()), salt));
     }
 }
Пример #11
0
 public static byte[] HashPassword(Pharmacist pharmacist, string password)
 {
     using (var service = new PharmacistService())
     {
         var salt = CreateSalt(32);
         pharmacist.PasswordSalt = salt;
         pharmacist.PasswordHash = GenerateSaltedHash(Encoding.ASCII.GetBytes(password), pharmacist.PasswordSalt);
         service.Update(pharmacist);
         return(pharmacist.PasswordHash);
     }
 }
Пример #12
0
 public JsonResult GetAllPharmacists()
 {
     using (var service = new PharmacistService())
     {
         List <PharmacistModel> result = new List <PharmacistModel>();
         var test = service.GetAll();
         //make a model to hold this
         foreach (var t in test)
         {
             result.Add(new PharmacistModel(t));
         }
         return(Json(result));
     }
 }
Пример #13
0
        protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //get the username
                        FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
                        JavaScriptSerializer      serializer = new JavaScriptSerializer();

                        PPOKPrincipalSerializeModel serializeModel = serializer.Deserialize <PPOKPrincipalSerializeModel>(authTicket.UserData);

                        PPOKPrincipal newUser = new PPOKPrincipal(serializeModel.Email);
                        switch (serializeModel.Type)
                        {
                        case AccountTypes.Pharmacist:
                        case AccountTypes.Admin:
                            using (var service = new PharmacistService())
                            {
                                newUser = new PPOKPrincipal(service.Get(serializeModel.Code), serializeModel.Pharmacy.Code);
                            }
                            break;

                        case AccountTypes.Patient:
                            using (var service = new PatientService())
                            {
                                newUser = new PPOKPrincipal(service.Get(serializeModel.Code));
                            }
                            break;

                        case AccountTypes.System:
                            using (var service = new SystemAdminService())
                            {
                                newUser = new PPOKPrincipal(service.Get(serializeModel.Code));
                            }
                            break;
                        }

                        HttpContext.Current.User = newUser;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        //somehting went wrong
                    }
                }
            }
        }
Пример #14
0
 public static bool ResetPharmacistPassword(string token, Pharmacist pharmacist, byte[] newPasswordHash)
 {
     using (var service = new PharmacistTokenService())
     {
         var pharmacistToken = service.GetWhere(PharmacistTokenService.TokenCol == token).FirstOrDefault();
         if (pharmacistToken != null && pharmacist != null && pharmacistToken.Expires > DateTime.Now.ToUniversalTime() && pharmacistToken.Pharmacist.Code == pharmacist.Code)
         {
             service.Delete(pharmacistToken.Code);
             using (var pharmacistService = new PharmacistService())
             {
                 pharmacist.PasswordHash = newPasswordHash;
                 pharmacistService.Update(pharmacist);
             }
             return(true);
         }
         return(false);
     }
 }
Пример #15
0
        public JsonResult Fill(int id)
        {
            Pharmacist pharm = new Pharmacist();

            using (var pharService = new PharmacistService())
            {
                pharm = pharService.Get(User.Code);
            }
            using (var service = new EventService())
            {
                var Er = service.Get(id);
                using (var fillservice = new FillHistoryService())
                {
                    FillHistory history = new FillHistory(Er.Refills.FirstOrDefault(), pharm, DateTime.Now);
                    fillservice.Create(history);
                }
                EventProcessingService.SendEvent(Er, User.Pharmacy.Code);
                return(Json(true));
            }
        }
Пример #16
0
        public ActionResult Login(string email, string password)
        {
            if (PPOKPrincipal.IsValid(email, password))
            {
                using (var PharmService = new PharmacistService())
                    using (var SysService = new SystemAdminService())
                    {
                        Pharmacist  pharmacist = PharmService.GetWhere(PharmacistService.EmailCol == email).FirstOrDefault();
                        SystemAdmin admin      = SysService.GetWhere(SystemAdminService.EmailCol == email).FirstOrDefault();
                        var         logins     = new LoginModel(email);

                        if (logins.pharmacyList.Count > 1)
                        {
                            if (admin != null)
                            {
                                makeAuthTicket(new PPOKPrincipalSerializeModel(admin));
                            }
                            else
                            {
                                makeAuthTicket(new PPOKPrincipalSerializeModel(pharmacist));
                            }
                            return(View("PharmacySelect", logins));
                        }
                        else if (admin != null)
                        {
                            var serializedAdmin = new PPOKPrincipalSerializeModel(admin);
                            makeAuthTicket(serializedAdmin);
                            return(RedirectToAction("Index", "SystemAdmin"));
                        }
                        else if (pharmacist != null)
                        {
                            var serializedPharmacist = new PPOKPrincipalSerializeModel(pharmacist);
                            makeAuthTicket(serializedPharmacist);
                            return(RedirectToAction("Index", "LandingPage"));
                        }
                    }
            }
            ViewBag.Error = "Invalid username/password combination";
            return(View("Index"));
        }
Пример #17
0
 public ActionResult EditPharmacist(int Code, int PharmacyCode, string FirstName, string LastName, string Email, string Phone)
 {
     Phone = Regex.Replace(Phone, @"[^A-Za-z0-9]+", "");
     if (Phone.Length == 10)
     {
         Phone = "1" + Phone;
     }
     using (var service = new PharmacistService())
     {
         Pharmacist p = service.Get(Code);
         if (p != null)
         {
             p.FirstName = FirstName;
             p.LastName  = LastName;
             p.Phone     = Phone;
             p.Email     = Email;
             service.Update(p);
         }
         return(RedirectToAction("SinglePharmacy", new RouteValueDictionary(
                                     new { controller = "SystemAdmin", action = "SinglePharmacy", Id = PharmacyCode })));
     }
 }
Пример #18
0
        public static bool IsValid(string email, string password)
        {
            using (var db = new PharmacistService())
                using (var adminDB = new SystemAdminService())
                {
                    var pharmacist = db.GetWhere(PharmacistService.EmailCol == email).FirstOrDefault();
                    var admin      = adminDB.GetWhere(SystemAdminService.EmailCol == email).FirstOrDefault();
                    if (pharmacist == null && admin == null)
                    {
                        return(false);
                    }

                    if (admin != null)
                    {
                        return(CompareByteArrays(admin.PasswordHash, GenerateSaltedHash(Encoding.ASCII.GetBytes(password), admin.PasswordSalt)));
                    }
                    if (pharmacist != null)
                    {
                        return(CompareByteArrays(pharmacist.PasswordHash, GenerateSaltedHash(Encoding.ASCII.GetBytes(password), pharmacist.PasswordSalt)));
                    }
                    return(false);
                }
        }
Пример #19
0
        public static void Test()
        {
            try
            {
                Console.WriteLine("Connecting to database...");
                using (var init = new InitDatabaseService())
                {
                    Console.WriteLine("Connection successful.\nResetting the database...");
                    init.Reset();
                    Console.WriteLine("Reset successful.\nLoading data...");

                    //create dummy pharmacy
                    Pharmacy pharm = new Pharmacy(1, "CSV Pharmacy", "19187661052", "1400 chrissartin street");
                    using (var service = new PharmacyService())
                    {
                        service.Create(pharm);
                    }
                    //create dummy patient
                    Patient patient  = new Patient(1, "Chris", "Sartin", new DateTime(2000, DateTime.Today.Month, DateTime.Today.Day), "77777", "19183994836", "*****@*****.**", pharm);
                    Patient patient1 = new Patient(2, "Matthew", "Miller", new DateTime(2000, DateTime.Today.Month, DateTime.Today.Day), "8675309", "19187661052", "*****@*****.**", pharm);

                    using (var service = new PatientService())
                    {
                        service.Create(patient);
                        service.Create(patient1);
                    }
                    //create dummy drug
                    Drug drug = new Drug(1, "Taco Medication");
                    using (var service = new DrugService())
                    {
                        service.Create(drug);
                    }
                    //create dummy prescription
                    Prescription prescription  = new Prescription(1, patient, drug, 7, 7);
                    Prescription prescription1 = new Prescription(2, patient1, drug, 6, 6);

                    using (var service = new PrescriptionService())
                    {
                        service.Create(prescription);
                        service.Create(prescription1);
                    }
                    EventRefill RefillEvent;

                    //create dummy event
                    using (var service = new EventService())
                    {
                        //create dummy eventRefill
                        Event Event  = new Event(patient, "this is a message", EventStatus.ToSend, EventType.REFILL);
                        Event Event1 = new Event(patient, "refill test event", EventStatus.Sent, EventType.REFILL);
                        Event Event2 = new Event(patient1, "this is a test", EventStatus.Fill, EventType.REFILL);
                        RefillEvent = new EventRefill(prescription, Event);
                        EventRefill RefillEvent1 = new EventRefill(prescription1, Event1);
                        EventRefill RefillEvent2 = new EventRefill(prescription1, Event2);
                        using (var service2 = new EventRefillService())
                        {
                            service.Create(Event);
                            service2.Create(RefillEvent);

                            service.Create(Event1);
                            service2.Create(RefillEvent1);

                            service.Create(Event2);
                            service2.Create(RefillEvent2);
                        }

                        //create dummy birthdayevent
                        Event BirthdayEvent = new Event(patient, "this is a message", EventStatus.ToSend, EventType.BIRTHDAY);
                        service.Create(BirthdayEvent);

                        //create dummy recallevent
                        Event = new Event(patient, "this is a message", EventStatus.ToSend, EventType.REFILL);
                        EventRecall RecallEvent = new EventRecall(Event);
                        using (var service2 = new EventRecallService())
                        {
                            service.Create(Event);
                            service2.Create(RecallEvent);
                        }

                        //create dummy eventhistory
                        EventHistory history = new EventHistory(Event, EventStatus.InActive, new DateTime(2000, 7, 14));
                        using (var service2 = new EventHistoryService())
                        {
                            service2.Create(history);
                        }
                    }

                    //create dummy pharmacist in the pharmacy
                    Pharmacist pharmacist  = new Pharmacist("James", "Taco", "*****@*****.**", "18884443333", new byte[] { 0 }, new byte[] { 0 });
                    Pharmacist pharmacist1 = new Pharmacist("Matthew", "Miller", "*****@*****.**", "19187661052", new byte[] { 0 }, new byte[] { 0 });
                    Pharmacist pharmacist2 = new Pharmacist("Luke", "Thorne", "*****@*****.**", "14056932048", new byte[] { 0 }, new byte[] { 0 });
                    Pharmacist pharmacist3 = new Pharmacist("Emily", "Pielemeier", "*****@*****.**", "13177536066", new byte[] { 0 }, new byte[] { 0 });
                    Pharmacist pharmacist4 = new Pharmacist("Tom", "Hartnett", "*****@*****.**", "14696671743", new byte[] { 0 }, new byte[] { 0 });

                    using (var service = new PharmacistService())
                    {
                        service.Create(pharmacist);
                        service.Create(pharmacist1);
                        service.Create(pharmacist2);
                        service.Create(pharmacist3);
                        service.Create(pharmacist4);
                    }


                    //create dummy fillhistory
                    FillHistory fill = new FillHistory(RefillEvent, pharmacist, new DateTime(2000, 7, 14));
                    using (var service = new FillHistoryService())
                    {
                        service.Create(fill);
                    }

                    //create dummy sysadmins (us)
                    SystemAdmin admin  = new SystemAdmin("testing", "the stuff", "*****@*****.**", "19184661052", new byte[] { 0 }, new byte[] { 0 });
                    SystemAdmin admin1 = new SystemAdmin("Tom", "Hartnett", "*****@*****.**", "14696671743", new byte[] { 0 }, new byte[] { 0 });
                    SystemAdmin admin2 = new SystemAdmin("Luke", "Thorne", "*****@*****.**", "14056932048", new byte[] { 0 }, new byte[] { 0 });
                    SystemAdmin admin3 = new SystemAdmin("Jon", "Hartnett", "*****@*****.**", "14696671064", new byte[] { 0 }, new byte[] { 0 });
                    SystemAdmin admin4 = new SystemAdmin("Emily", "Pielemeier", "*****@*****.**", "13177536066", new byte[] { 0 }, new byte[] { 0 });
                    using (var service = new SystemAdminService())
                    {
                        service.Create(admin);
                        service.Create(admin1);
                        service.Create(admin2);
                        service.Create(admin3);
                        service.Create(admin4);
                    }

                    //create dummy job
                    Job job = new Job(pharm, pharmacist, true, false);
                    using (var service = new JobService())
                    {
                        service.Create(job);
                        Job j1 = new Job(pharm, pharmacist1, true, true);
                        service.Create(j1);
                        Job j2 = new Job(pharm, pharmacist2, true, true);
                        service.Create(j2);
                        Job j3 = new Job(pharm, pharmacist3, true, true);
                        service.Create(j3);
                        Job j4 = new Job(pharm, pharmacist4, true, true);
                        service.Create(j4);
                    }

                    init.LoadFromFile(@"..\..\App_Data\Scrubbed_Data.xlsx - Sheet1.csv", pharm);
                    Console.WriteLine("Loading data successful.\nAll tests successful...");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.ReadKey();
            }
        }