public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] RoleGroups roleGroups)
        {
            if (id != roleGroups.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(roleGroups);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RoleGroupsExists(roleGroups.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(roleGroups));
        }
示例#2
0
        public async Task <IActionResult> PutRoleGroups([FromRoute] int id, [FromBody] RoleGroups roleGroups)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != roleGroups.Id)
            {
                return(BadRequest());
            }

            _context.Entry(roleGroups).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoleGroupsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#3
0
        private int GetTemplateIndex()
        {
            if (!DesignMode && Page != null && Page.Request.IsAuthenticated)
            {
                IPrincipal user           = LoginUtil.GetUser(this);
                int        roleGroupIndex = -1;

                // Unlikely but possible for Page.Request.IsAuthenticated to be true and
                // user to be null.
                if (user != null)
                {
                    roleGroupIndex = RoleGroups.GetMatchingRoleGroupInternal(user);
                }

                if (roleGroupIndex >= 0)
                {
                    return(roleGroupIndex + roleGroupStartingIndex);
                }
                else
                {
                    return(loggedInTemplateIndex);
                }
            }
            else
            {
                return(anonymousTemplateIndex);
            }
        }
        // GET: Appointments
        public async Task <IActionResult> Index()
        {
            List <string> roles = new List <string>();

            var medicalcenterContext = _context.Appointments.Include(a => a.Clinic)
                                       .Include(a => a.CreatedByNavigation).Include(a => a.Doctor)
                                       .Include(a => a.Doctor.User)
                                       .Include(a => a.Patient.User)
                                       .Include(a => a.Patient).Include(a => a.Session);

            if (!string.IsNullOrEmpty(HttpContext.Session.GetString("user_id")))
            {
                int user_id = int.Parse(HttpContext.Session.GetString("user_id"));
                var user    = _context.Users
                              .Include(u => u.UserRoleGroups)
                              .ThenInclude(rg => rg.RoleGroup)
                              .ThenInclude(rco => rco.RoleCarryOuts)
                              .ThenInclude(r => r.Role)
                              .SingleOrDefault(u => u.Id == user_id);


                foreach (UserRoleGroups urg in user.UserRoleGroups)
                {
                    RoleGroups rg = urg.RoleGroup;



                    foreach (RoleCarryOuts rco in rg.RoleCarryOuts)
                    {
                        roles.Add(rco.Role.Description);
                    }
                }

                if (roles.BinarySearch("patient") >= 0)
                {
                    var medicalcenterContextPatient = _context.Appointments.Include(a => a.Clinic)
                                                      .Include(a => a.CreatedByNavigation).Include(a => a.Doctor)
                                                      .Include(a => a.Patient).Include(a => a.Session).Include(a => a.Doctor.User)
                                                      .Include(a => a.Patient.User)
                                                      .Where(a => a.Patient.UserId == user_id);
                    return(View(await medicalcenterContextPatient.ToListAsync()));
                }
                else
                {
                    var medicalcenterContextPatient = _context.Appointments.Include(a => a.Clinic)
                                                      .Include(a => a.CreatedByNavigation).Include(a => a.Doctor)
                                                      .Include(a => a.Doctor.User)
                                                      .Include(a => a.Patient).Include(a => a.Session)
                                                      .Include(a => a.Patient.User)
                                                      .Where(a => a.ClinicId == user.ClinicId);
                    return(View(await medicalcenterContextPatient.ToListAsync()));
                }
            }



            return(View(await medicalcenterContext.ToListAsync()));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] RoleGroups roleGroups)
        {
            if (ModelState.IsValid)
            {
                _context.Add(roleGroups);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(roleGroups));
        }
示例#6
0
        public async Task <IActionResult> PostRoleGroups([FromBody] RoleGroups roleGroups)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.RoleGroups.Add(roleGroups);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRoleGroups", new { id = roleGroups.Id }, roleGroups));
        }
示例#7
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            RoleGroups = await _context.RoleGroups.FirstOrDefaultAsync(m => m.Id == id);

            if (RoleGroups == null)
            {
                return(NotFound());
            }
            return(Page());
        }
示例#8
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            RoleGroups = await _context.RoleGroups.FindAsync(id);

            if (RoleGroups != null)
            {
                _context.RoleGroups.Remove(RoleGroups);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public List <OrgUnitContainsRoleGroupLink> FetchAssociatedRoleGroups()
        {
            List <OrgUnitContainsRoleGroupLink> roleGroups;

            try
            {
                roleGroups = RoleGroups.Where(i => i.Active && !i.IsDeleted && i.RoleGroupId.Equals(Id)).ToList();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Debug.WriteLine(e);

                return(null);
            }

            return(roleGroups);
        }
 private RenderFragment GetView()
 {
     if (!(_user.Identity?.IsAuthenticated ?? false))
     {
         return(AnonymousTemplate);
     }
     else
     {
         var roleGroup = RoleGroups.GetRoleGroup(_user);
         if (roleGroup != null)
         {
             return(roleGroup.ChildContent);
         }
         else
         {
             return(LoggedInTemplate);
         }
     }
 }
示例#11
0
        public ActionResult MobileLogin(string email, string password)
        {
            if (email == null || password == null)
            {
                return(Ok("Invalid Request"));
            }

            //Users userParam = request;
            string pass = Hashing.CalculateMD5Hash(password);



            var user = _context.Users
                       .Include(u => u.Patients)
                       .Include("Patients.Appointments.Prescriptions")
                       .Include(u => u.Inventories)
                       .Include(u => u.UserRoleGroups)
                       .ThenInclude(rg => rg.RoleGroup)
                       .ThenInclude(rco => rco.RoleCarryOuts)
                       .ThenInclude(r => r.Role)
                       .SingleOrDefault(u => u.Email == email &&
                                        u.Password == pass);

            //var appointments = _context.Appointments.Include(a => a.Clinic)
            //            .Include(a => a.CreatedByNavigation).Include(a => a.Doctor)
            //            .Include(a => a.Patient).Include(a => a.Session)
            //            .Where(a => a.Patient.UserId == user.Id );

            //user.Appointments = appointments;


            if (user == null)
            {
                return(Ok("Invalid Credentials, User Not Found"));
                //return Forbid("Invalid Credentials");
            }

            //List<string> roles = new List<string>();

            //foreach(UserRoleGroups urg in user.UserRoleGroups)
            //{
            //    RoleGroups rg = urg.RoleGroup;

            //    foreach(RoleCarryOuts rco in rg.RoleCarryOuts)
            //    {
            //        roles.Add(rco.Role.Description);
            //    }
            //}

            //string role = user.UserRoleGroups.SingleOrDefault().RoleGroup.RoleCarryOuts.SingleOrDefault().Role.Description;

            //security key
            string securityKey = _appSettings.JwtKey;
            //symmetric security key
            var symmetricSecurityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(securityKey));

            //signing credentials
            var signingCredentials = new SigningCredentials(symmetricSecurityKey, SecurityAlgorithms.HmacSha256Signature);

            bool isManager    = false;
            bool isDoctor     = false;
            bool isAdmin      = false;
            bool isPatient    = false;
            bool isAccountant = false;

            //add claims
            var claims = new List <Claim>();

            //claims.Add(new Claim(ClaimTypes.Role, "Administrator"));
            //claims.Add(new Claim(ClaimTypes.Role, "Reader"));
            //claims.Add(new Claim("RoleGroup", role));
            claims.Add(new Claim(ClaimTypes.Name, user.Name));
            claims.Add(new Claim(ClaimTypes.Email, user.Email));

            HttpContext.Session.SetString("Name", user.Name);
            HttpContext.Session.SetString("Email", user.Email);

            foreach (UserRoleGroups urg in user.UserRoleGroups)
            {
                RoleGroups rg = urg.RoleGroup;

                if (rg.Name == "managers")
                {
                    HttpContext.Session.SetString("isManager", "1");
                    isManager = true;
                }
                if (rg.Name == "accountants")
                {
                    HttpContext.Session.SetString("isAccountant", "1");
                    isAccountant = true;
                }

                if (rg.Name == "patients")
                {
                    HttpContext.Session.SetString("isPatient", "1");
                    isPatient = true;
                }

                if (rg.Name == "doctors")
                {
                    HttpContext.Session.SetString("isDoctor", "1");
                    isDoctor = true;
                }

                if (rg.Name == "admins")
                {
                    HttpContext.Session.SetString("isAdmin", "1");
                    isAdmin = true;
                }

                claims.Add(new Claim("RoleGroup", rg.Name));

                foreach (RoleCarryOuts rco in rg.RoleCarryOuts)
                {
                    claims.Add(new Claim(ClaimTypes.Role, rco.Role.Description));
                }
            }

            claims.Add(new Claim("Id", user.Id.ToString()));


            //create token
            var token = new JwtSecurityToken(
                issuer: "mutants",
                audience: "users",
                expires: DateTime.Now.AddHours(1),
                signingCredentials: signingCredentials
                , claims: claims
                );

            user.Password = null;
            user.Token    = new JwtSecurityTokenHandler().WriteToken(token);

            HttpContext.Session.SetString("user_id", user.Id.ToString());
            HttpContext.Session.SetObject("user", user);

            //return token
            return(Ok(user));
        }
示例#12
0
        public ActionResult Login(Users userParam)
        {
            string pass = Hashing.CalculateMD5Hash(userParam.Password);
            var    user = _context.Users
                          .Include(u => u.Appointments)
                          .Include(u => u.UserRoleGroups)
                          .ThenInclude(rg => rg.RoleGroup)
                          .ThenInclude(rco => rco.RoleCarryOuts)
                          .ThenInclude(r => r.Role)
                          .SingleOrDefault(u => u.Email == userParam.Email &&
                                           u.Password == pass);


            if (user == null)
            {
                return(Ok("Invalid Credentials"));
                //return Forbid("Invalid Credentials");
            }

            //List<string> roles = new List<string>();

            //foreach(UserRoleGroups urg in user.UserRoleGroups)
            //{
            //    RoleGroups rg = urg.RoleGroup;

            //    foreach(RoleCarryOuts rco in rg.RoleCarryOuts)
            //    {
            //        roles.Add(rco.Role.Description);
            //    }
            //}

            //string role = user.UserRoleGroups.SingleOrDefault().RoleGroup.RoleCarryOuts.SingleOrDefault().Role.Description;

            //security key
            string securityKey = _appSettings.JwtKey;
            //symmetric security key
            var symmetricSecurityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(securityKey));

            //signing credentials
            var signingCredentials = new SigningCredentials(symmetricSecurityKey, SecurityAlgorithms.HmacSha256Signature);

            //add claims
            var claims = new List <Claim>();

            //claims.Add(new Claim(ClaimTypes.Role, "Administrator"));
            //claims.Add(new Claim(ClaimTypes.Role, "Reader"));
            //claims.Add(new Claim("RoleGroup", role));
            claims.Add(new Claim(ClaimTypes.Name, user.Name));
            claims.Add(new Claim(ClaimTypes.Email, user.Email));

            foreach (UserRoleGroups urg in user.UserRoleGroups)
            {
                RoleGroups rg = urg.RoleGroup;

                claims.Add(new Claim("RoleGroup", rg.Name));

                foreach (RoleCarryOuts rco in rg.RoleCarryOuts)
                {
                    claims.Add(new Claim(ClaimTypes.Role, rco.Role.Description));
                }
            }

            claims.Add(new Claim("Id", user.Id.ToString()));


            //create token
            var token = new JwtSecurityToken(
                issuer: "mutants",
                audience: "users",
                expires: DateTime.Now.AddHours(1),
                signingCredentials: signingCredentials
                , claims: claims
                );

            user.Password = null;
            user.Token    = new JwtSecurityTokenHandler().WriteToken(token);

            HttpContext.Session.SetString("user_id", user.Id.ToString());
            HttpContext.Session.SetObject("user", user);

            //return token
            return(Ok(user));
        }