Esempio n. 1
0
        // GET: MyPanel
        public ActionResult Index()
        {
            var userforadmin    = new ApplicationUser();
            var userforhospital = new ApplicationUserForHospitals();
            var userforengineer = new ApplicationUserForEngineers();



            if (User.IsInRole("AdminUser"))
            {
                var adminUsers = Userdb.Users.OfType <ApplicationUser>().ToList();
                userforadmin = adminUsers.FirstOrDefault(m => m.UserName == User.Identity.Name);
                return(View("IndexForAdminInfo", userforadmin));
            }
            else if (User.IsInRole("HospitalUsers"))
            {
                ///new code is written here
                ///in this code the Hospital information including instruments is loaded
                GetHospitalViewInformation();
                //pass through the view to show detail information
                return(View("IndexForHospitalInfo", indexForHospitalInfoViewModel));
            }
            else if (User.IsInRole("EngineerUsers"))
            {
                var engineerUsers = Userdb.Users.OfType <ApplicationUserForEngineers>().ToList();
                userforengineer = engineerUsers.FirstOrDefault(m => m.UserName == User.Identity.Name);
                return(View("IndexForEngineerInfo", userforengineer));
            }
            else
            {
                return(Content("db.MyPanelViewModels.ToList()"));
            }
        }
Esempio n. 2
0
        public async Task <ActionResult> Register(RegisterViewModel Adminmodel, HospitalUserRegisterViewModel Hospitalmodel, EngineerUserRegisterViewModel Engineermodel)
        {
            ViewBag.Bool = false;
            if ((string)TempData["userNoo"] == "AdminUser")
            {
                ModelState.Remove("HospitalName");
                ModelState.Remove("YearsOfWork");
                ModelState.Remove("ExpertInInstruments");
                var user = new ApplicationUser {
                    City = Adminmodel.City, Province = Adminmodel.Province, PhoneNumber = Adminmodel.PhoneNumberr, NameAndLastName = Adminmodel.NameAndLastName, Email = Adminmodel.UserNamee, UserName = Adminmodel.UserNamee, userRole = (string)TempData["userNoo"]
                };
                if (ModelState.IsValid)
                {
                    var result = await UserManager.CreateAsync(user, Adminmodel.Password);

                    AddErrors(result);
                }

                if (ModelState.IsValid)
                {
                    var result = await UserManager.AddToRoleAsync(user.Id, user.userRole);

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    AddErrors(result);
                    if (ModelState.IsValid)
                    {
                        AdminUser adminuser = new AdminUser();
                        adminuser.NameAndLastName = user.NameAndLastName;
                        adminuser.City            = user.City;
                        adminuser.PhoneNumberr    = user.PhoneNumber;
                        adminuser.UserNamee       = user.UserName;
                        adminuser.Province        = user.Province;
                        APPAuthentication.AppAuthentication appAuthentication = new APPAuthentication.AppAuthentication(adminuser);
                        string x = appAuthentication.Registeration();
                        return(RedirectToAction("Index", "MyPanel"));
                    }
                    else
                    {
                        TempData["userNoo"] = "AdminUser";
                        ///////////////////////////////////////////////////////////////////////////////////
                        List <SelectListItem> list = new List <SelectListItem>();
                        foreach (var city in db.T_City)
                        {
                            list.Add(new SelectListItem()
                            {
                                Value = city.City_Name.ToString(), Text = city.City_Name.ToString()
                            });
                        }
                        ViewBag.Cities = list;
                        List <SelectListItem> listt = new List <SelectListItem>();
                        foreach (var state in db.T_State)
                        {
                            listt.Add(new SelectListItem()
                            {
                                Value = state.State_Name.ToString(), Text = state.State_Name.ToString()
                            });
                        }
                        ViewBag.Province = listt;
                        ////////////////////////////////////////////////////////////////////////////////////////////////
                        if (user.Province != null)
                        {
                            ViewBag.Cities = GetRelatedCity(user.Province);
                            return(PartialView("_Register"));
                        }
                        else
                        {
                            return(View("RegisterForAdmin"));
                        }
                    }
                }
                else
                {
                    //Returning Model For possible errors (Admin Model)
                    TempData["userNoo"] = "AdminUser";

                    ///////////////////////////////////////////////////////////////////////////////////////////////////////
                    List <SelectListItem> list = new List <SelectListItem>();
                    foreach (var city in db.T_City)
                    {
                        list.Add(new SelectListItem()
                        {
                            Value = city.City_Name.ToString(), Text = city.City_Name.ToString()
                        });
                    }
                    ViewBag.Cities = list;
                    List <SelectListItem> listt = new List <SelectListItem>();
                    foreach (var state in db.T_State)
                    {
                        listt.Add(new SelectListItem()
                        {
                            Value = state.State_Name.ToString(), Text = state.State_Name.ToString()
                        });
                    }
                    ViewBag.Province = listt;
                    ///////////////////////////////////////////////////////////////////////////////////////////////////////
                    if (user.Province != null)
                    {
                        ViewBag.Cities = GetRelatedCity(user.Province);
                        return(PartialView("_Register"));
                    }
                    else
                    {
                        return(View("RegisterForAdmin"));
                    }
                }
            }
            else if ((string)TempData["userNoo"] == "HospitalUsers")
            {
                ModelState.Remove("ExpertInInstruments");
                ModelState.Remove("YearsOfWork");
                var user = new ApplicationUserForHospitals {
                    City = Hospitalmodel.City, Province = Hospitalmodel.Province, HospitalName = Hospitalmodel.HospitalName, NameAndLastName = Hospitalmodel.NameAndLastName, Email = Hospitalmodel.UserNamee, UserName = Hospitalmodel.UserNamee, PhoneNumber = Hospitalmodel.PhoneNumberr, userRole = (string)TempData["userNoo"]
                };
                if (ModelState.IsValid)
                {
                    var result = await UserManager.CreateAsync(user, Hospitalmodel.Password);

                    AddErrors(result);
                }

                if (ModelState.IsValid)
                {
                    var result = await UserManager.AddToRoleAsync(user.Id, user.userRole);

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    AddErrors(result);
                    if (ModelState.IsValid)
                    {
                        HospitalUser hospitaluser = new HospitalUser();
                        hospitaluser.City            = user.City;
                        hospitaluser.PhoneNumberr    = user.PhoneNumber;
                        hospitaluser.Province        = user.Province;
                        hospitaluser.UserNamee       = user.UserName;
                        hospitaluser.NameAndLastName = user.NameAndLastName;
                        hospitaluser.HospitalName    = user.HospitalName;
                        APPAuthentication.AppAuthentication appAuthentication = new APPAuthentication.AppAuthentication(hospitaluser);
                        string x = appAuthentication.Registeration();
                        return(RedirectToAction("Index", "MyPanel"));
                    }
                    else
                    {
                        TempData["userNoo"] = "HospitalUsers";
                        ///////////////////////////////////////////////////////////////////////////////////////////////////////
                        List <SelectListItem> list = new List <SelectListItem>();
                        foreach (var city in db.T_City)
                        {
                            list.Add(new SelectListItem()
                            {
                                Value = city.City_Name.ToString(), Text = city.City_Name.ToString()
                            });
                        }
                        ViewBag.Cities = list;
                        List <SelectListItem> listt = new List <SelectListItem>();
                        foreach (var state in db.T_State)
                        {
                            listt.Add(new SelectListItem()
                            {
                                Value = state.State_Name.ToString(), Text = state.State_Name.ToString()
                            });
                        }
                        ViewBag.Province = listt;
                        ///////////////////////////////////////////////////////////////////////////////////////////////////////
                        return(View("RegisterForHospital"));
                    }
                }
                else
                {
                    TempData["userNoo"] = "HospitalUsers";
                    ///////////////////////////////////////////////////////////////////////////////////////////////////////
                    List <SelectListItem> list = new List <SelectListItem>();
                    foreach (var city in db.T_City)
                    {
                        list.Add(new SelectListItem()
                        {
                            Value = city.City_Name.ToString(), Text = city.City_Name.ToString()
                        });
                    }
                    ViewBag.Cities = list;
                    List <SelectListItem> listt = new List <SelectListItem>();
                    foreach (var state in db.T_State)
                    {
                        listt.Add(new SelectListItem()
                        {
                            Value = state.State_Name.ToString(), Text = state.State_Name.ToString()
                        });
                    }
                    ViewBag.Province = listt;
                    ///////////////////////////////////////////////////////////////////////////////////////////////////////
                    return(View("RegisterForHospital"));
                }
            }
            else if ((string)TempData["userNoo"] == "EngineerUsers")
            {
                ModelState.Remove("HospitalName");
                var user = new ApplicationUserForEngineers {
                    City = Engineermodel.City, Province = Engineermodel.Province, ExpertInInstruments = Engineermodel.ExpertInInstruments, YearsOfWork = Engineermodel.YearsOfWork, NameAndLastName = Engineermodel.NameAndLastName, Email = Engineermodel.UserNamee, UserName = Engineermodel.UserNamee, PhoneNumber = Engineermodel.PhoneNumberr, userRole = (string)TempData["userNoo"]
                };
                if (ModelState.IsValid)
                {
                    var result = await UserManager.CreateAsync(user, Engineermodel.Password);

                    AddErrors(result);
                }
                if (ModelState.IsValid)
                {
                    var result = await UserManager.AddToRoleAsync(user.Id, user.userRole);

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    AddErrors(result);
                    if (ModelState.IsValid)
                    {
                        EngineerUser engineeruser = new EngineerUser();
                        engineeruser.NameAndLastName = user.NameAndLastName;
                        engineeruser.instruments     = user.ExpertInInstruments;
                        engineeruser.City            = user.City;
                        engineeruser.PhoneNumberr    = user.PhoneNumber;
                        engineeruser.Province        = user.Province;
                        engineeruser.UserNamee       = user.UserName;
                        APPAuthentication.AppAuthentication appAuthentication = new APPAuthentication.AppAuthentication(engineeruser);
                        string x = appAuthentication.Registeration();
                        return(RedirectToAction("Index", "MyPanel"));
                    }
                    else
                    {
                        TempData["userNoo"] = "EngineerUsers";
                        ///////////////////////////////////////////////////////////////////////////////////////////////////////
                        List <SelectListItem> list = new List <SelectListItem>();
                        foreach (var city in db.T_City)
                        {
                            list.Add(new SelectListItem()
                            {
                                Value = city.City_Name.ToString(), Text = city.City_Name.ToString()
                            });
                        }
                        ViewBag.Cities = list;
                        List <SelectListItem> listt = new List <SelectListItem>();
                        foreach (var state in db.T_State)
                        {
                            listt.Add(new SelectListItem()
                            {
                                Value = state.State_Name.ToString(), Text = state.State_Name.ToString()
                            });
                        }
                        ViewBag.Province = listt;
                        ///////////////////////////////////////////////////////////////////////////////////////////////////////
                        return(View("RegisterForEngineer"));
                    }
                }
                else
                {
                    //Returning Model For possible errors (Engineer Model)
                    TempData["userNoo"] = "EngineerUsers";
                    ///////////////////////////////////////////////////////////////////////////////////////////////////////
                    List <SelectListItem> list = new List <SelectListItem>();
                    foreach (var city in db.T_City)
                    {
                        list.Add(new SelectListItem()
                        {
                            Value = city.City_Name.ToString(), Text = city.City_Name.ToString()
                        });
                    }
                    ViewBag.Cities = list;
                    List <SelectListItem> listt = new List <SelectListItem>();
                    foreach (var state in db.T_State)
                    {
                        listt.Add(new SelectListItem()
                        {
                            Value = state.State_Name.ToString(), Text = state.State_Name.ToString()
                        });
                    }
                    ViewBag.Province = listt;
                    ///////////////////////////////////////////////////////////////////////////////////////////////////////
                    return(View("RegisterForEngineer"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }