Example #1
0
        public async Task <IActionResult> Dashboard()
        {
            if (hospitalId != null && roleName == "Hospital")
            {
                try
                {
                    var bedResource = await _hospitalService.GetAllBedsForHospital(hospitalId);

                    if (bedResource == null)
                    {
                        bedResource = new BedResource();
                    }

                    var patients = await _patientService.GetPatientsForHospital(hospitalId);

                    if (patients == null)
                    {
                        patients = new List <PatientFullData>();
                    }

                    var recieptionist = await _recieptionistService.GetRecieptionistFullData(userId);

                    List <PatientFullData> notitficationList = new List <PatientFullData>();

                    if (recieptionist != null || recieptionist.NotificationData != null)
                    {
                        foreach (var notification in recieptionist.NotificationData)
                        {
                            notitficationList.Add(JsonConvert.DeserializeObject <PatientFullData>(notification.NotificationText));
                        }
                    }

                    HospitalStatisticsViewModel hospitalStatistics = new HospitalStatisticsViewModel()
                    {
                        Notifications        = notitficationList,
                        AvailableBedsCount   = bedResource.AvailableBeds.Count,
                        UmAvailableBedsCount = bedResource.UnAvailableBeds.Count,
                        PatientsCount        = patients.Count()
                    };
                    return(View(hospitalStatistics));
                }
                catch
                {
                    ViewBag.ErrorLoadingPatients = true;
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(RedirectToAction("Login", "Account"));
        }
Example #2
0
        public async Task <IActionResult> Login(LoginInfoResources loginInfoResources)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(loginInfoResources));
                }
                else
                {
                    var userInfo = await _accountService.Login(loginInfoResources);

                    if (userInfo == null)
                    {
                        ViewBag.userFounded    = false;
                        ViewBag.userAuthorized = false;
                        return(View());
                    }

                    if (userInfo.RoleName.Equals("Hospital"))
                    {
                        var recieptionistData = await _recieptionistService.GetRecieptionistFullData(userInfo.Id);

                        TempData["recieptionistData"] = JsonConvert.SerializeObject(recieptionistData);
                        TempData.Keep();

                        _session.SetString(Email, userInfo.Email);
                        _session.SetString(UserId, userInfo.Id.ToString());
                        _session.SetString(RoleName, userInfo.RoleName);
                        _session.SetString(Hospital, recieptionistData.HospitalData.HospitalData.Id.ToString());


                        User.AddIdentity(new System.Security.Claims.ClaimsIdentity
                        {
                            Label = _session.GetString(Email)
                        });



                        ViewBag.userEmail = userInfo.Email;
                        return(RedirectToAction("Index", "Home"));
                    }
                    else if (userInfo.RoleName.Equals("Authority"))
                    {
                        var authorityData = await _authorityService.AuthorityFullData(userInfo.Id);

                        TempData["authorityData"] = JsonConvert.SerializeObject(authorityData);
                        TempData.Keep();

                        _session.SetString(Email, userInfo.Email);
                        _session.SetString(UserId, userInfo.Id.ToString());
                        _session.SetString(RoleName, userInfo.RoleName);
                        _session.SetString(Authority, authorityData.AuthorityFullData.Id.ToString());

                        ViewBag.userEmail = userInfo.Email;
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ViewBag.userFounded    = true;
                        ViewBag.userAuthorized = false;
                        return(View());
                    }
                }
            }

            catch
            {
                ViewBag.userFounded    = true;
                ViewBag.userAuthorized = false;
                return(View());
            }
        }