コード例 #1
0
        public ActionResult CreateUser(string Name, string Surname, string UserType, string Username, string Password, string ConfirmedPassword, string btnSubmit)
        {
            {
                if (btnSubmit == "Submit")
                {
                    if (Password != ConfirmedPassword)
                    {
                        ViewBag.PasswordMatchError = "Passwords do not match, please re-enter!";
                    }
                    else
                    {
                        User   newUser   = new User();
                        Doctor newDoctor = new Doctor();

                        newDoctor.Doctor_Email = Name;
                        newDoctor.Doctor_Name  = Surname;

                        UserType CheckForUserType = db.UserTypes.Where(X => X.Description == UserType).FirstOrDefault();
                        if (CheckForUserType != null)
                        {
                            newUser.UserType = CheckForUserType.ID;
                        }
                        newUser.UserEmail    = Username;
                        newUser.UserPassword = GenerateHashedPassword(Password);
                        newDoctor.Doctor_ID  = newUser.UserID;

                        db.Doctors.Add(newDoctor);
                        db.Users.Add(newUser);
                        db.SaveChanges();
                        return(View("Login"));
                    }
                }
                return(View());
            }
        }
コード例 #2
0
        public ActionResult Upload(HttpPostedFileBase jsonFile)
        {
            {
                using (OnlinePharmacyEntities db = new OnlinePharmacyEntities())
                {
                    if (!jsonFile.FileName.EndsWith(".json"))
                    {
                        ViewBag.Error = "Invalid file type(Only JSON file allowed)";
                    }
                    else
                    {
                        jsonFile.SaveAs(Server.MapPath("~/FileUpload/" + Path.GetFileName(jsonFile.FileName)));
                        StreamReader        streamReader = new StreamReader(Server.MapPath("~/FileUpload/" + Path.GetFileName(jsonFile.FileName)));
                        string              data         = streamReader.ReadToEnd();
                        List <Prescription> Prescription = JsonConvert.DeserializeObject <List <Prescription> >(data);

                        Prescription.ForEach(p =>
                        {
                            Prescription prescription = new Prescription()
                            {
                                Prescription_Date = p.Prescription_Date,
                                PrescriptionLines = p.PrescriptionLines,
                            };
                            db.Prescriptions.Add(prescription);
                            db.SaveChanges();
                        });
                        ViewBag.Success = "File uploaded Successfully..";
                    }
                }
                return(View());
            }
        }
コード例 #3
0
        public void RefreshGUID(OnlinePharmacyEntities db)
        {
            db.Configuration.ProxyCreationEnabled = false;
            user.GUID       = Guid.NewGuid().ToString();
            user.GUIDExpiry = DateTime.Now.AddMinutes(30);
            int guids = db.Users.Where(usr => usr.GUID == user.GUID).Count();

            if (guids > 0)
            {
                RefreshGUID(db);
            }
            else
            {
                var u = db.Users.Where(zz => zz.UserID == user.UserID).FirstOrDefault();
                db.Entry(u).CurrentValues.SetValues(user);
                db.SaveChanges();
            }
        }