public ActionResult EditProfile()
        {
            using (var db = new MainDbContext())
            {

                string firstname = User.Identity.Name;
                var NurseModel = db.Nurse.FirstOrDefault(u => u.FirstName.Equals(firstname));

                var searchKeyAdd = db.Nurse.Select(u => u.Key_Address);
                var materializeAddKey = searchKeyAdd.ToList();
                var KeyAdd = materializeAddKey[0];
                var AddModel = db.Address.FirstOrDefault(u => u.Id.Equals(KeyAdd));

                var searchKeyCon = db.Nurse.Select(u => u.Key_Contact);
                var materializeConKey = searchKeyCon.ToList();
                var KeyCon = materializeConKey[0];
                var ConModel = db.Contact.FirstOrDefault(u => u.Id.Equals(KeyCon));

                var searchUserKey = db.Nurse.Select(u => u.Key_Users);
                var materializeUserKey = searchUserKey.ToList();
                var KeyUser = materializeUserKey[0];
                var UsersModel = db.Users.FirstOrDefault(u => u.Id.Equals(KeyUser));

                var password = CustomDecrypt.Decrypt(UsersModel.Password);

                UsersModel.Password = password;

                var viewmodel = new NurseModel
                {
                    Contact = ConModel,
                    Address = AddModel,
                    Nurse = NurseModel,
                    Users = UsersModel
                };

                return View(viewmodel);
            }
        }
 public CategoryRepository(MainDbContext mainDbContext, ISessionServices sessionServices) : base(mainDbContext, sessionServices)
 {
 }
示例#3
0
        public ActionResult Index()
        {
            var db = new MainDbContext();

            return(View(db.Lists.ToList()));
        }
示例#4
0
 public CrawlLinkRepository(LoadDbContext loadDbContext)
 {
     _dbContext = loadDbContext.DbContext;
 }
示例#5
0
 public UserTokenRepo(MainDbContext mainDbContext)
 {
     this.mainDbContext = mainDbContext;
 }
示例#6
0
 public EfRepostory(MainDbContext context)
 {
     this.context = context;
 }
        public ActionResult EditProfile(FDRModel model)
        {
            if (ModelState.IsValid)
            {
                using (var db = new MainDbContext())
                {
                    string firstname = User.Identity.Name;

                    //Get Doctor
                    var FdrModel = db.FDR.FirstOrDefault(u => u.FirstName.Equals(firstname));
                    FdrModel.HospName = model.FDR.HospName;
                    FdrModel.EmployeeId = model.FDR.EmployeeId;
                    FdrModel.LicenseNo = model.FDR.LicenseNo;
                    FdrModel.Specialization = model.FDR.Specialization;
                    FdrModel.FirstName = model.FDR.FirstName;
                    FdrModel.MiddleName = model.FDR.MiddleName;
                    FdrModel.LastName = model.FDR.LastName;
                    FdrModel.Email = model.FDR.Email;
                    FdrModel.DateBirth = model.FDR.DateBirth;
                    FdrModel.Sex = model.FDR.Sex;
                    FdrModel.SecQuestion = model.FDR.SecQuestion;
                    FdrModel.SecAnswer = model.FDR.SecAnswer;

                    db.Entry(FdrModel).State = EntityState.Modified;

                    // Get the Address
                    var searchKeyAdd = db.FDR.Select(u => u.Key_Address);
                    var materializeAddKey = searchKeyAdd.ToList();
                    var KeyAdd = materializeAddKey[0];
                    var AddModel = db.Address.FirstOrDefault(u => u.Id.Equals(KeyAdd));

                    AddModel.City = model.Address.City;
                    AddModel.Province = model.Address.Province;
                    AddModel.Zipcode = model.Address.Zipcode;
                    AddModel.AddressType = model.Address.AddressType;

                    db.Entry(AddModel).State = EntityState.Modified;

                    // Get the Contact
                    var searchKeyCon = db.FDR.Select(u => u.Key_Contact);
                    var materializeConKey = searchKeyCon.ToList();
                    var KeyCon = materializeConKey[0];
                    var ConModel = db.Contact.FirstOrDefault(u => u.Id.Equals(KeyCon));

                    ConModel.MobileNo = model.Contact.MobileNo;
                    ConModel.PhoneNo = model.Contact.PhoneNo;

                    db.Entry(ConModel).State = EntityState.Modified;

                    // Get the Users
                    var searchUserKey = db.FDR.Select(u => u.Key_Users);
                    var materializeUserKey = searchUserKey.ToList();
                    var KeyUser = materializeUserKey[0];
                    var UsersModel = db.Users.FirstOrDefault(u => u.Id.Equals(KeyUser));

                    var encryptedPassword = CustomEnrypt.Encrypt(model.Users.Password);
                    UsersModel.Username = model.Users.Username;
                    UsersModel.Password = encryptedPassword;

                    db.Entry(UsersModel).State = EntityState.Modified;

                    db.SaveChanges();

                    var identity = new ClaimsIdentity(new[] {
                           new Claim(ClaimTypes.Name, FdrModel.FirstName),
                           new Claim(ClaimTypes.Role, "FDR")
                           }, "ApplicationCookie");

                    var ctx = Request.GetOwinContext();

                    var authManager = ctx.Authentication;

                    authManager.SignIn(identity);

                    return RedirectToAction("Index", "FDR");
                }

            }

            return View(model);
        }
 public EFMainRepository()
 {
     this.context = new MainDbContext();
 }
示例#9
0
 public Repository(MainDbContext newContext)
 {
     myContext = newContext;
 }
示例#10
0
 public CalendarController(MainDbContext dbContext)
 {
     db = dbContext;
 }
示例#11
0
 public GetTagQueryHandler(MainDbContext dbContext)
 {
     _dbContext = dbContext;
 }
示例#12
0
 public AccountModel()
 {
     context = new MainDbContext();
 }
示例#13
0
 public ProductsLogic(MainDbContext context) : base(context)
 {
 }
示例#14
0
 public ScenarioRepository(MainDbContext context)
 {
     _context = context;
 }
示例#15
0
 public HomeController(MainDbContext mainDbContext)
 {
     _context = mainDbContext;
 }
示例#16
0
        public ActionResult Login(LoginModel2 model)
        {
            if(!ModelState.IsValid)
            //if (model.CaptchaCodeText !=  Convert.ToString(Session["Captcha"])) //check if input == to captcha shown
            {
                if (Session["time"] == null)
                {

                    model.CapImage = "data:image/png;base64," + Convert.ToBase64String(new Utility().VerificationTextGenerator());
                    model.CapImageText = Convert.ToString(Session["Captcha"]);

                    return View("Sample", model);
                }
                else
                {
                    time = (int)Session["time"];
                    time++;
                    Session["time"] = time;
                    Response.Write("Wrong times: " + time.ToString());
                    if (time >= 3)
                    {
                        model.CapImage = "data:image/png;base64," + Convert.ToBase64String(new Utility().VerificationTextGenerator());
                        model.CapImageText = Convert.ToString(Session["Captcha"]);

                        return View("Sample", model);//Returns the view with the input values so that the user doesn't have to retype again

                    }
                } //Returns the view with the input values so that the user doesn't have to retype again

                /*if (Session["time"] == null)
                        {
                            Session["time"] = time + 1;
                            Response.Write("Wrong times: 1");
                        }
                        else
                {
                    time = (int)Session["time"];
                    time++;
                    Session["time"] = time;
                    Response.Write("Wrong times: " + time.ToString());
                    if (time >= 3)
                    {
                        model.CapImage = "data:image/png;base64," + Convert.ToBase64String(new Utility().VerificationTextGenerator());
                        model.CapImageText = Convert.ToString(Session["Captcha"]);

                        return View("Sample", model);//Returns the view with the input values so that the user doesn't have to retype again

                    }
                }*/
                return View();
            }
            else
            {
                //MainDbContext db = new MainDbContext();
                using (var db = new MainDbContext())
                {
                    var usernameCheck = db.Users.FirstOrDefault(u => u.Username == model.Users.Username);
                    var getPassword = db.Users.Where(u => u.Username == model.Users.Username).Select(u => u.Password);
                    var materializePassword = getPassword.ToList();
                    if (materializePassword.Count != 0)
                    {
                        var password = materializePassword[0];
                        var decryptedPassword = CustomDecrypt.Decrypt(password);
                        if (model.Users.Username != null && model.Users.Password == decryptedPassword)
                        {
                            var searchrole = db.Role.Where(u => u.Id == usernameCheck.Key_Role).Select(u => u.RoleType);
                            var materializeRole = searchrole.ToList();
                            var role = materializeRole[0];
                            var ctx = Request.GetOwinContext();
                            var authManager = ctx.Authentication;
                            if (role == "doctor")
                            {
                                var checkname = db.Doctor.FirstOrDefault(u => u.Key_Users == usernameCheck.Id);
                                var getname = db.Doctor.Where(u => u.Id == checkname.Id).Select(u => u.FirstName);
                                var materializeName = getname.ToList();
                                var name = materializeName[0];

                                var identity = new ClaimsIdentity(new[] {
                           new Claim(ClaimTypes.Name, name),
                           new Claim(ClaimTypes.Role, role)
                           }, "ApplicationCookie");

                                authManager.SignIn(identity);
                                return RedirectToAction("Index", "Doctor");
                            }
                            else if (role == "FDR")
                            {
                                var checkname = db.FDR.FirstOrDefault(u => u.Key_Users == usernameCheck.Id);
                                //var getname = db.PersonInfo.Where(u => u.Id == checkname.Key_PersonInfo).Select(u => u.FirstName);
                                var getname = db.FDR.Select(u => u.FirstName);
                                var materializeName = getname.ToList();
                                var name = materializeName[0];
                                var identity = new ClaimsIdentity(new[] {
                           new Claim(ClaimTypes.Name, name),
                           new Claim(ClaimTypes.Role, role)
                           }, "ApplicationCookie");

                                authManager.SignIn(identity);
                                return RedirectToAction("Index", "FDR");
                            }
                            else if (role == "nurse")
                            {
                                /*var checkname = db.Nurse.FirstOrDefault(u => u.Key_Users == usernameCheck.Id);
                                 var getname = db.PersonInfo.Where(u => u.Id == checkname.Key_PersonInfo).Select(u => u.FirstName);
                                 var materializeName = getname.ToList();
                                 var name = materializeName[0];*/
                                var identity = new ClaimsIdentity(new[] {
                           //new Claim(ClaimTypes.Name, name),
                           new Claim(ClaimTypes.Role, role)
                           }, "ApplicationCookie");

                                authManager.SignIn(identity);
                                return RedirectToAction("Index", "Nurse");
                            }
                            else if (role == "administrator")
                            {
                                /*var checkname = db.Admin.FirstOrDefault(u => u.Key_Users == usernameCheck.Id);
                                 var getname = db.PersonInfo.Where(u => u.Id == checkname.Key_PersonInfo).Select(u => u.FirstName);
                                 var materializeName = getname.ToList();
                                 var name = materializeName[0];*/
                                var identity = new ClaimsIdentity(new[] {
                           //new Claim(ClaimTypes.Name, name),
                           new Claim(ClaimTypes.Role, role)
                           }, "ApplicationCookie");

                                authManager.SignIn(identity);
                                return RedirectToAction("Index", "Admin");
                            }

                        }
                        if (Session["time"] == null)
                        {
                            Session["time"] = time + 1;
                            Response.Write("Wrong times: 1");
                        }
                        else
                        {
                            time = (int)Session["time"];
                            time++;
                            Session["time"] = time;
                            Response.Write("Wrong times: " + time.ToString());
                            if (time >= 3)
                            {
                                model.CapImage = "data:image/png;base64," + Convert.ToBase64String(new Utility().VerificationTextGenerator());
                                model.CapImageText = Convert.ToString(Session["Captcha"]);

                                return View("Sample", model);//Returns the view with the input values so that the user doesn't have to retype again

                            }
                        }
                    }
                    else
                    {

                        if (Session["time"] == null)
                        {
                            Session["time"] = time + 1;
                            Response.Write("Wrong times: 1");
                        }
                        else
                        {
                            time = (int)Session["time"];
                            time++;
                            Session["time"] = time;
                            Response.Write("Wrong times: " + time.ToString());
                            if (time >= 3)
                            {
                                model.CapImage = "data:image/png;base64," + Convert.ToBase64String(new Utility().VerificationTextGenerator());
                                model.CapImageText = Convert.ToString(Session["Captcha"]);

                                return View("Sample", model);//Returns the view with the input values so that the user doesn't have to retype again

                            }
                        }
                        //model.CapImage = "data:image/png;base64," + Convert.ToBase64String(new Utility().VerificationTextGenerator());
                        //model.CapImageText = Convert.ToString(Session["Captcha"]);
                        ModelState.AddModelError("", "Invalid username or password"); //Should always be declared on the end of an action method
                    }

                    return View(model);
                }
            }
        }
示例#17
0
 protected AppControllerBase(MainDbContext db, IUserEventsService userEventsService)
 {
     Db = db;
     UserEventsService = userEventsService;
 }
示例#18
0
        public ActionResult CreatePatient(PatientModel model)
        {
            if (ModelState.IsValid)
            {
                using (var db = new MainDbContext())
                {
                    var queryUser = db.Users.FirstOrDefault(u => u.Username == model.Users.Username);
                    if (queryUser == null)
                    {
                        var encryptedPassword = CustomEnrypt.Encrypt(model.Users.Password);

                        var patient = db.Patient.Create();
                        var address = db.Address.Create();
                        var contact = db.Contact.Create();
                        var user = db.Users.Create();
                        var role = db.Role.Create();
                        patient.FirstName = model.Patient.FirstName;
                        patient.MiddleName = model.Patient.MiddleName;
                        patient.LastName = model.Patient.LastName;
                        patient.Email = model.Patient.Email;
                        patient.DateBirth = model.Patient.DateBirth;
                        patient.Sex = model.Patient.Sex;
                        patient.MaritalStatus = model.Patient.MaritalStatus;
                        patient.HoursWorked = model.Patient.HoursWorked;
                        patient.CompanyName = model.Patient.CompanyName;
                        patient.Occupation = model.Patient.Occupation;
                        address.AddressType = model.Address.AddressType;
                        address.City = model.Address.City;
                        address.Province = model.Address.Province;
                        address.Zipcode = model.Address.Zipcode;
                        user.Username = model.Users.Username;
                        user.Password = encryptedPassword;
                        user.Password = encryptedPassword;
                        contact.MobileNo = model.Contact.MobileNo;
                        contact.PhoneNo = model.Contact.PhoneNo;

                        db.Address.Add(address);
                        db.Contact.Add(contact);
                        db.Role.Add(role);
                        db.SaveChanges();

                        user.Key_Role = role.Id;
                        db.Users.Add(user);
                        db.SaveChanges();

                        patient.Key_Address = address.Id;
                        patient.Key_Contact = contact.Id;
                        db.Patient.Add(patient);
                        db.SaveChanges();

                        return RedirectToAction("CreatePatient", "FDR");
                    }
                    else
                    {
                        return RedirectToAction("CreatePatient", "FDR");
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "One or more fields have been");
            }
            return View();
        }
 public BolgeLiderController(MainDbContext context)
 {
     _context = context;
 }
示例#20
0
 public TRepository(MainDbContext dbContext)
 {
     _dbContext = dbContext;
 }
 public UserRoleRepository(MainDbContext mainDbContext, ISessionServices sessionServices) : base(mainDbContext, sessionServices)
 {
 }
 public DefaultTenantBuilder(MainDbContext context)
 {
     _context = context;
 }
示例#23
0
 public OrderRepository(MainDbContext context) : base(context)
 {
 }
 public GenericRepository(MainDbContext dbContext)
 {
     //…          //set internal values
     Db = dbContext;
 }
示例#25
0
        public ActionResult Login(Models.UserLoginInfo uli_cl)
        {
            //  check if there are any errors inside the form's values
            if (!ModelState.IsValid)
            {
                return(View(uli_cl));
            }

            using (var dbLogin = new MainDbContext())
            {
                var userLoginInfo = dbLogin.applicationUser.FirstOrDefault(u => u.UserName == uli_cl.username);

                if (userLoginInfo != null)
                {
                    var getPassword         = dbLogin.applicationUser.Where(u => u.UserName == uli_cl.username).Select(u => u.Password);
                    var materializePassword = getPassword.ToList();
                    var password            = materializePassword[0];
                    var decryptedPassword   = CustomDecrypt.Decrypt(password);

                    if (uli_cl.password == decryptedPassword && userLoginInfo.UserName == uli_cl.username)
                    {
                        var getUserFullName     = dbLogin.applicationUser.Where(u => u.UserName == uli_cl.username).Select(u => u.UserFullName);
                        var materializeFullName = getUserFullName.ToList();
                        var userFullName        = materializeFullName[0];

                        //  we need to store the employer somewhere
                        var getUserEmployer         = dbLogin.applicationUser.Where(u => u.UserName == uli_cl.username).Select(u => u.UserEmployer);
                        var materializeUserEmployer = getUserEmployer.ToList();
                        var userEmployer            = materializeUserEmployer[0];


                        var getUserRole         = dbLogin.applicationUser.Where(u => u.UserName == uli_cl.username).Select(u => u.UserRole);
                        var materializeUserRole = getUserRole.ToList();
                        var userRole            = materializeUserRole[0];


                        var getUserId         = dbLogin.applicationUser.Where(u => u.UserName == uli_cl.username).Select(u => u.Id);
                        var materializeUserId = getUserId.ToList();
                        var userId            = materializeUserId[0].ToString();


                        //  create an identity with name and role
                        var identity = new ClaimsIdentity(new[] {
                            new Claim(ClaimTypes.Name, userFullName),
                            new Claim(ClaimTypes.Role, userRole),
                            new Claim("userId", userId),
                            new Claim("clientName", userEmployer),
                        }, "ApplicationCookie");

                        //  actually login with identity
                        var ctx         = Request.GetOwinContext();
                        var authManager = ctx.Authentication;
                        authManager.SignIn(identity);

                        if (userRole == RoleNames.ROLE_ADMIN)
                        {
                            return(RedirectToAction("Index", "Admin"));
                        }
                        else if (userRole == RoleNames.ROLE_REGISTRAR)
                        {
                            return(RedirectToAction("Index", "Registrar"));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Client"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid username or password");
                        return(View(uli_cl));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid username or password");
                    return(View(uli_cl));
                }
            }
        }
示例#26
0
 public DefaultSettingsCreator(MainDbContext context)
 {
     _context = context;
 }
示例#27
0
 public QQAcountManageService()
 {
     m_MainDbContext = new MainDbContext();
 }
 public ProductSubCategoriesController(MainDbContext context) : base(context)
 {
 }
示例#29
0
 //Depedency injection implemented on constructor.Instatiate db object
 public EfOfferRepository(MainDbContext db)
 {
     this.db = db;
 }
示例#30
0
 public SimAndDevicesController(UserRepository userRepository, MainDbContext context)
 {
     _userRepository = userRepository;
     _context        = context;
 }
示例#31
0
 public AccountsController(MainDbContext context)
 {
     db      = context;
     service = new SecurityService();
 }
示例#32
0
        public ActionResult Registration(LoginModel model)
        {
            if (    ModelState.IsValid)
            {
                using (var db = new MainDbContext())
                {
                    var queryUser = db.Users.FirstOrDefault(u => u.Username == model.Users.Username);
                    if (queryUser == null)
                    {
                        var encryptedPassword = CustomEnrypt.Encrypt(model.Users.Password);
                        var user = db.Users.Create();
                        var role = db.Role.Create();
                        user.Username = model.Users.Username;
                        user.Password = encryptedPassword;
                        role.RoleType = "administrator";
                        db.Role.Add(role);
                        db.SaveChanges();

                        user.Key_Role = role.Id;
                        db.Users.Add(user);
                        db.SaveChanges();

                        return RedirectToAction("Login", "Auth");
                    }
                    else
                    {
                        return RedirectToAction("Registration", "Auth");
                    }

                }
            }
            else
            {
                ModelState.AddModelError("", "One or more fields have been");
            }
            return View();
        }
示例#33
0
 public AdminController(MainDbContext db, UserManager <IdentityUser> userManager)
 {
     _db          = db;
     _userManager = userManager;
 }
示例#34
0
 public CartModel()
 {
     db = new MainDbContext();
 }
 public TenantRoleAndUserBuilder(MainDbContext context, int tenantId)
 {
     _context  = context;
     _tenantId = tenantId;
 }
        // GET: Doctor
        public ActionResult Index()
        {
            using (var db = new MainDbContext())
            {
               // /*using (SqlCommand cmd = new SqlCommand())
               // {
               //     cmd.CommandType = CommandType.StoredProcedure;
               //     cmd.CommandText = "DOCUMENT_SELECT";
               //     cmd.Parameters.Add("FirstName");
               // }
                string firstname = User.Identity.Name;
                var DocModel = db.Doctor.FirstOrDefault(u => u.FirstName.Equals(firstname));

                // Construct the viewmodel
                Doctor model = new Doctor();
                model.FirstName = DocModel.FirstName;

                return View(model);

            }
        }
示例#37
0
 public CategoryRepository(MainDbContext context)
     : base(context)
 {
 }
示例#38
0
        public ActionResult CreatePatient()
        {
            /*string firstname = User.Identity.Name;
                var profilemodel = db.PersonInfo.FirstOrDefault(u => u.FirstName.Equals(firstname));

                var searchkeycont = db.PersonInfo.Where(u => u.FirstName == firstname).Select(u => u.Key_Contact);
                var materializeKey = searchkeycont.ToList();
                var Keycont = materializeKey[0];
                var contactmodel = db.Contact.FirstOrDefault(u => u.Id.Equals(Keycont));

                var searchkeyadd = db.PersonInfo.Where(u => u.FirstName == firstname).Select(u => u.Key_Address);
                var materializeKeyAdd = searchkeyadd.ToList();
                var Keyadd = materializeKeyAdd[0];
                var addmodel = db.Address.FirstOrDefault(u => u.Id.Equals(Keyadd));

                var searchdoc = db.PersonInfo.Where(u => u.FirstName == firstname).Select(u => u.Id);
                var materializedoc = searchdoc.ToList();
                var Keydoc = materializedoc[0];
                var docmodel = db.Doctor.FirstOrDefault(u => u.Key_PersonInfo.Equals(Keydoc));

                var searchuser = db.Doctor.Where(u => u.Key_PersonInfo == Keydoc).Select(u => u.Key_Users);
                var materializeuser = searchuser.ToList();
                var Keyuser = materializeuser[0];
                var usermodel = db.Users.FirstOrDefault(u => u.Id.Equals(Keyuser));*/

               //  var searchrole = db.Role.Where(u => u.RoleType == "doctor").Select(u => u.Id);

               // var materializeKey = searchrole.ToList();

               // var searchuser = db.Users.Where(u => u.Key_Role == u.Id).Select(u => u.Id);

                /*
                for (int i = 0; i < materializeKey.Count ; i++)
                {
                    var Keyrole = materializeKey[i];

                    var searchuser = db.Users.Where(u => u.Key_Role == Keyrole).Select(u => u.Id);

                    var materializeUserId = searchrole.ToList();

                    for (int j = 0; j < materializeUserId.Count; j++)
                    {
                        var Keyuser = materializeUserId[j];
                        var searchdoctor = db.Doctor.Where(u => u.Key_Users == Keyuser).Select(u => u.Key_PersonInfo);

                        var materializeDoctorId = searchdoctor.ToList();

                        for (int k = 0; k < materializeDoctorId.Count; k++)
                        {
                            var Keypersoninfo = materializeDoctorId[k];
                            var searchpersoninfo = db.PersonInfo.Where(u => u.Id == Keypersoninfo).Select(u => u.Id);

                            var materializePersoninfoId = searchpersoninfo.ToList();

                            for (int l = 0; l < materializePersoninfoId.Count; l++)
                            {
                                var Namepersoninfo = materializePersoninfoId[l];
                                var profilemodel = db.PersonInfo.FirstOrDefault(u => u.Id.Equals(Namepersoninfo));
                                var viewmodel = new PatientModel
                                {
                                    PersonInfo = profilemodel
                                };
                            }
                        }

                    }

                }*/

                MainDbContext db = new MainDbContext();

                    ViewBag.FirstName = new SelectList(db.Doctor, "Id", "FirstName");

                    return View();

                /*var viewmodel = new PatientModel
                {
                    PersonInfo = profilemodel,
                    Contact = contactmodel,
                    Address = addmodel,
                    Doctor = docmodel,
                    Users = usermodel,
                    Role = rolemodel
                }; */
        }
示例#39
0
        public ActionResult Index()
        {
            var db = new MainDbContext();

            return(View(/*db.Alumnos.ToList()*/));
        }
示例#40
0
        // GET: FDR
        public ActionResult Index()
        {
            using (var db = new MainDbContext())
            {

                string firstname = User.Identity.Name;
                var FdrModel = db.FDR.FirstOrDefault(u => u.FirstName.Equals(firstname));

                // Construct the viewmodel
                FDR model = new FDR();
                model.FirstName = FdrModel.FirstName;

                return View(model);

            }
        }
        public ActionResult CreateFDR(FDRModel model)
        {
            if (ModelState.IsValid)
            {
                using (var db = new MainDbContext())
                {
                    var queryUser = db.Users.FirstOrDefault(u => u.Username == model.Users.Username);
                    if (queryUser == null)
                    {

                            var encryptedPassword = CustomEnrypt.Encrypt(model.Users.Password);

                            var fdr = db.FDR.Create();
                            var address = db.Address.Create();
                            var contact = db.Contact.Create();
                            var user = db.Users.Create();
                            var role = db.Role.Create();
                            fdr.FirstName = model.FDR.FirstName;
                            fdr.MiddleName = model.FDR.MiddleName;
                            fdr.LastName = model.FDR.LastName;
                            fdr.Email = model.FDR.Email;
                            fdr.EmployeeId = model.FDR.EmployeeId;
                            fdr.LicenseNo = model.FDR.LicenseNo;
                            fdr.HospName = model.FDR.HospName;
                            fdr.Specialization = model.FDR.Specialization;
                            fdr.DateBirth = model.FDR.DateBirth;
                            fdr.Sex = model.FDR.Sex;
                            address.AddressType = model.Address.AddressType;
                            address.City = model.Address.City;
                            address.Province = model.Address.Province;
                            address.Zipcode = model.Address.Zipcode;
                            user.Username = model.Users.Username;
                            user.Password = encryptedPassword;
                            user.Password = encryptedPassword;
                            role.RoleType = "FDR";
                            fdr.SecQuestion = model.FDR.SecQuestion;
                            fdr.SecAnswer = model.FDR.SecAnswer;
                            contact.MobileNo = model.Contact.MobileNo;
                            contact.PhoneNo = model.Contact.PhoneNo;

                            db.Address.Add(address);
                            db.Contact.Add(contact);
                            db.Role.Add(role);
                            db.SaveChanges();

                            user.Key_Role = role.Id;
                            db.Users.Add(user);
                            db.SaveChanges();

                            fdr.Key_Users = user.Id;
                            fdr.Key_Address = address.Id;
                            fdr.Key_Contact = contact.Id;
                            db.FDR.Add(fdr);
                            db.SaveChanges();

                            return RedirectToAction("CreateFDR", "Admin");
                        }
                        else
                        {
                            return RedirectToAction("CreateFDR", "Admin");
                        }
                    }
            }
            else
            {
                ModelState.AddModelError("", "One or more fields have been");
            }
            return View();
        }