예제 #1
0
        /// <summary>
        /// Asigna y/o crea un rol
        /// </summary>
        /// <param name="pHealthInstitutionId"></param>
        /// <param name="pProfesionalId_ToAssign"></param>
        /// <param name="pUserId"></param>
        /// <param name="roleName"></param>
        public static void Profesional_UsersInRoles_Assign(Guid pHealthInstitutionId, Int32 pProfesionalId_ToAssign, Guid pUserId, string roleName)
        {
            Back.BE.HealthInstitution_Profesional wHealthInstitution_Profesional = new Back.BE.HealthInstitution_Profesional();
            Back.BE.HealtInstitute_UsersInRoles   wHealtInstitute_UsersInRoles   = new BE.HealtInstitute_UsersInRoles();
            using (Health.Back.BE.HealthEntities dc = new Health.Back.BE.HealthEntities(Common.CnnString_Entities))
            {
                //Si no existe la relacion del profesional con la inst.. se genera
                if (!dc.HealthInstitution_Profesional.Any(p =>
                                                          p.HealthInstitutionId.Equals(pHealthInstitutionId) &&
                                                          p.Profesional.IdProfesional.Equals(pProfesionalId_ToAssign)))
                {
                    wHealthInstitution_Profesional.HealthInstitutionId = pHealthInstitutionId;
                    wHealthInstitution_Profesional.ProfesionalId       = pProfesionalId_ToAssign;
                    wHealthInstitution_Profesional.UserId      = pUserId;
                    wHealthInstitution_Profesional.IsLockedOut = false;
                    wHealthInstitution_Profesional.ActiveFlag  = true;

                    if (roleName.Equals("inst_owner") || roleName.Equals("inst_admin"))
                    {
                        wHealthInstitution_Profesional.IsAdmin = roleName.Equals("inst_admin");
                        wHealthInstitution_Profesional.IsOwner = roleName.Equals("inst_owner");
                    }
                    dc.HealthInstitution_Profesional.AddObject(wHealthInstitution_Profesional);
                }


                wHealtInstitute_UsersInRoles.UserId = pUserId;
                wHealtInstitute_UsersInRoles.HealthInstitutionId = pHealthInstitutionId;
                wHealtInstitute_UsersInRoles.RoleName            = roleName;

                dc.HealtInstitute_UsersInRoles.AddObject(wHealtInstitute_UsersInRoles);

                dc.SaveChanges();
            }
        }
예제 #2
0
        /// <summary>
        /// Crea HealtInstitute_UsersInRoles = inst_admin
        /// Crea HealthInstitution_Profesional
        /// </summary>
        /// <param name="pHealthInstitutionId"></param>
        /// <param name="pProfesionalId_ToAssign"></param>
        /// <param name="pUserId"></param>
        public static void Profesional_Associate_As_AdminOwner(Guid pHealthInstitutionId, Int32 pProfesionalId_ToAssign, Guid pUserId, string rolname)
        {
            Back.BE.HealthInstitution_Profesional wHealthInstitution_Profesional = new Back.BE.HealthInstitution_Profesional();
            Back.BE.HealtInstitute_UsersInRoles   wHealtInstitute_UsersInRoles   = new BE.HealtInstitute_UsersInRoles();
            using (Health.Back.BE.HealthEntities dc = new Health.Back.BE.HealthEntities(Common.CnnString_Entities))
            {
                wHealtInstitute_UsersInRoles.UserId = pUserId;
                wHealtInstitute_UsersInRoles.HealthInstitutionId = pHealthInstitutionId;
                wHealtInstitute_UsersInRoles.RoleName            = rolname;

                wHealthInstitution_Profesional.IsAdmin             = true;
                wHealthInstitution_Profesional.HealthInstitutionId = pHealthInstitutionId;
                wHealthInstitution_Profesional.ProfesionalId       = pProfesionalId_ToAssign;
                wHealthInstitution_Profesional.UserId = pUserId;

                dc.HealthInstitution_Profesional.AddObject(wHealthInstitution_Profesional);
                dc.HealtInstitute_UsersInRoles.AddObject(wHealtInstitute_UsersInRoles);

                dc.SaveChanges();
            }
        }
예제 #3
0
        /// <summary>
        /// Crea una Institución
        /// Establece como profesional owner de  pHealthInstitution a pProfesionalId/pUserId
        /// </summary>
        /// <param name="pHealthInstitution">Institución</param>
        /// <param name="pProfesionalId">Profecional</param>
        /// <param name="pUserId"></param>
        public static void Create_From_Owner(Health.Back.BE.HealthInstitution pHealthInstitution, Int32 pProfesionalId, Guid pUserId)
        {
            Back.BE.HealthInstitution_Profesional wHealthInstitution_Profesional = new Back.BE.HealthInstitution_Profesional();
            Back.BE.HealtInstitute_UsersInRoles   wHealtInstitute_UsersInRoles   = new BE.HealtInstitute_UsersInRoles();

            using (Health.Back.BE.HealthEntities dc = new Health.Back.BE.HealthEntities(Common.CnnString_Entities))
            {
                //Busco la institución padre si existe
                var parentHI = dc.HealthInstitutions.Where(p => !p.HealthInstitutionIdParent.HasValue &&
                                                           p.HealthInstitution_Profesional.Any(prof => prof.ProfesionalId.Equals(pProfesionalId))).FirstOrDefault();
                if (parentHI != null)
                {
                    pHealthInstitution.HealthInstitutionIdParent = parentHI.HealthInstitutionId;
                }

                pHealthInstitution.HealthInstitutionId = Guid.NewGuid();
                pHealthInstitution.CreatedDate         = System.DateTime.Now;
                dc.HealthInstitutions.AddObject(pHealthInstitution);

                wHealthInstitution_Profesional.HealthInstitutionId = pHealthInstitution.HealthInstitutionId;
                wHealthInstitution_Profesional.ProfesionalId       = pProfesionalId;
                wHealthInstitution_Profesional.ActiveFlag          = true;
                wHealthInstitution_Profesional.UserId      = pUserId;
                wHealthInstitution_Profesional.IsLockedOut = false;
                wHealthInstitution_Profesional.IsOwner     = true;
                dc.HealthInstitution_Profesional.AddObject(wHealthInstitution_Profesional);


                wHealtInstitute_UsersInRoles.UserId = pUserId;
                wHealtInstitute_UsersInRoles.HealthInstitutionId = pHealthInstitution.HealthInstitutionId;
                wHealtInstitute_UsersInRoles.RoleName            = "inst_owner";

                dc.HealtInstitute_UsersInRoles.AddObject(wHealtInstitute_UsersInRoles);

                dc.SaveChanges();
            }
        }