예제 #1
0
        public static void fillCookie()
        {
            string  username = HttpContext.Current.User.Identity.Name;
            tbStaff staff    = StaffApiRequestHelper.getStaffData(username);

            SetCookie(staff.ID, staff.Name, staff.Username, staff.Role, staff.HospitalID ?? 0, staff.HospitalName);
        }
        public static async Task <tbStaff> Login(tbStaff staff)
        {
            var     url    = string.Format("api/Staff/login");
            tbStaff result = await ApiRequest <tbStaff> .PostRequest(url, staff);

            return(result);
        }
        public static tbStaff getStaffData(string username)
        {
            string  url      = string.Format("api/Staff/getStaffData?username={0}", username);
            tbStaff response = null;

            ApiRequest <tbStaff> .Get(url, out response);

            return(response);
        }
예제 #4
0
        public async Task <ActionResult> Index(tbStaff staff)
        {
            tbStaff staffdata = await StaffApiRequestHelper.Login(staff);

            if (staffdata != null)
            {
                FormsAuthentication.SetAuthCookie(staffdata.Username, false);
                SetCookie(staffdata.ID, staffdata.Name, staffdata.Username, staffdata.Role, staffdata.HospitalID ?? 0, staffdata.HospitalName);
                return(RedirectToAction("Index", "DoctorSchedule"));
            }
            else
            {
                ViewBag.Status = "Unauthorize";
                return(View());
            }
        }
예제 #5
0
        public static tbStaff getStaff()
        {
            tbStaff staff = new tbStaff();

            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                var Cookie = HttpContext.Current.Request.Cookies[CookieName];
                if (Cookie != null)
                {
                    staff.ID           = Convert.ToInt32(Cookie["ID"]);
                    staff.Name         = HttpUtility.UrlDecode(Cookie["Name"]);
                    staff.Username     = HttpUtility.UrlDecode(Cookie["Username"]);
                    staff.Role         = Cookie["Role"];
                    staff.HospitalID   = Convert.ToInt32(Cookie["HospitalID"]);
                    staff.HospitalName = HttpUtility.UrlDecode(Cookie["HospitalName"]);
                    return(staff);
                }
                else
                {
                    fillCookie();
                    var Cookie2 = HttpContext.Current.Request.Cookies[CookieName];
                    if (Cookie2 != null)
                    {
                        staff.ID           = Convert.ToInt32(Cookie2["ID"]);
                        staff.Name         = HttpUtility.UrlDecode(Cookie2["Name"]);
                        staff.Username     = HttpUtility.UrlDecode(Cookie2["Username"]);
                        staff.Role         = Cookie2["Role"];
                        staff.HospitalID   = Convert.ToInt32(Cookie2["HospitalID"]);
                        staff.HospitalName = HttpUtility.UrlDecode(Cookie2["HospitalName"]);
                    }
                    return(staff);
                }
            }
            else
            {
                return(staff);
            }
        }
예제 #6
0
        public HttpResponseMessage getStaffData(HttpRequestMessage request, String username)
        {
            tbStaff result = staffRepo.GetWithoutTracking().Where(a => a.Username == username).FirstOrDefault();

            return(request.CreateResponse <tbStaff>(HttpStatusCode.OK, result));
        }
예제 #7
0
        public HttpResponseMessage Login(HttpRequestMessage request, tbStaff login)
        {
            tbStaff result = staffRepo.GetWithoutTracking().Where(a => a.Username == login.Username && a.Password == login.Password).FirstOrDefault();

            return(request.CreateResponse <tbStaff>(HttpStatusCode.OK, result));
        }