//---------------------------------------- public bool InRoles(string roles) { if (string.IsNullOrWhiteSpace(roles)) { return(false); } var rolesArray = roles.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (var role in rolesArray) { bool hasRole; try { hasRole = DoctorRole.Any(p => string.Compare(p.Role.Code, role, true) == 0); } catch (NullReferenceException) { return(false); } if (hasRole) { return(true); } } return(false); }
public void TestConstructor() { var mafia = new MafiaRole(); var doctor = new DoctorRole(); var citizen = new PeacefulRole(); var localCity = new City(new List <IPerson>( new[] { new Person(citizen, doctor, "Bob"), new Person(citizen, mafia, "Alice"), new Person(citizen, null, "Ira"), }), Settings.Deadly.CityName); localCity.Roles.Count.Should().Be(3); localCity.Roles.Should().BeEquivalentTo(citizen, mafia, doctor); }
public bool MakeAdmin(int adminID, int roleID) { DoctorRole instance = new DoctorRole(); instance.DoctorID = adminID; instance.RoleID = roleID; dataBase.DoctorRole.InsertOnSubmit(instance); try { dataBase.DoctorRole.Context.SubmitChanges(); } catch { return(false); } return(true); }
private void ImportDoctors(JsonDataFileImporterReader importer) { var doctors = importer.Doctors(_filePath); foreach (var doctor in doctors) { var d = new Doctor { Name = doctor.Name }; foreach (var role in doctor.Roles) { var r = new DoctorRole { Doctor = d, RoleId = role.Value }; _context.Add(r); } _context.Add(d); } _context.SaveChanges(); }
public async Task Consume(ConsumeContext <IUserCreatedEvent> context) { var @event = context.Message; var role = new Role(@event.Role); var doctorRole = new DoctorRole(); if (role.Equals(doctorRole)) { var calendar = new Calendar(@event.AggregateId); await _repository.SaveAsync(calendar); await context.Publish <ICalendarCreatedEvent>(new { Version = calendar.Version, Timestamp = DateTimeOffset.UtcNow, MessageType = typeof(ICalendarCreatedEvent).Name, AggregateId = calendar.Id, WorkingHours = calendar.WorkingHours, UserId = calendar.UserId, UserEmail = @event.Email }); } }
/*private void UpdateXMLPacient(string resourceName) * { * XDocument doc = XDocument.Load(resourceName); * * UnitOfWork uow = new UnitOfWork(((DevExpress.ExpressApp.Xpo.XPObjectSpace)ObjectSpace).Session.DataLayer); * int counter = 0; * * foreach (XElement el in doc.Root.Element("ROWDATA").Elements("ROW")) * { * string fam = el.Attribute("FAM").Value; * string nam = el.Attribute("IM").Value; * string ot = el.Attribute("OT").Value; * Pacient pacient = uow.FindObject<Pacient>(CriteriaOperator.Parse("Fam=? AND Nam=? AND Ot=?", fam, nam, ot)); * if (pacient == null) * { * pacient = new Pacient(uow); * pacient.Fam = (el.Attribute("FAM").Value); * pacient.Nam = el.Attribute("IM").Value; * pacient.Ot = el.Attribute("OT").Value; * pacient.DR = el.Attribute("DR").Value == "" ? new DateTime(1900,1,1) : Convert.ToDateTime(el.Attribute("DR").Value); * pacient.Gender = el.Attribute("W").Value =="1" ? Gender.Мужской: Gender.Женский; * * pacient.Address.OKATO =el.Attribute("RN").Value; * pacient.Address.OKATOP = el.Attribute("PRN").Value; * pacient.Address.Street = el.Attribute("UL").Value; * pacient.Address.House = el.Attribute("DOM").Value; * pacient.Address.Build = el.Attribute("KOR").Value; * pacient.Address.Flat = el.Attribute("KV").Value; * * pacient.Document.Type = uow.FindObject<VidDocumenta>(CriteriaOperator.Parse("Code=?", el.Attribute("DOCTP").Value)); * pacient.Document.Serial = el.Attribute("DOCS").Value; * pacient.Document.Number = el.Attribute("DOCN").Value; * * var polis = new Polis(uow); * polis.Type = uow.FindObject<VidPolisa>(CriteriaOperator.Parse("Code=?", el.Attribute("OPDOC").Value)); * polis.Serial = el.Attribute("SPOL").Value; * polis.Number = el.Attribute("NPOL").Value; * pacient.Polises.Add(polis); * counter++; * } * else * { * if (pacient.Polises.Count == 0) * { * var polis = new Polis(uow); * polis.Type = uow.FindObject<VidPolisa>(CriteriaOperator.Parse("Code=?", el.Attribute("OPDOC").Value)); * polis.Serial = el.Attribute("SPOL").Value; * polis.Number = el.Attribute("NPOL").Value; * pacient.Polises.Add(polis); * counter++; * } * } * * if (counter % 1000 == 0) * { * uow.CommitChanges(); * uow.Dispose(); * uow = new UnitOfWork(((DevExpress.ExpressApp.Xpo.XPObjectSpace)ObjectSpace).Session.DataLayer); * } * } * }*/ private void SecurityRoles() { DoctorRole adminDoctorRole = ObjectSpace.FindObject <DoctorRole>(new BinaryOperator("Name", SecurityStrategy.AdministratorRoleName)); if (adminDoctorRole == null) { adminDoctorRole = ObjectSpace.CreateObject <DoctorRole>(); adminDoctorRole.Name = SecurityStrategy.AdministratorRoleName; adminDoctorRole.IsAdministrative = true; adminDoctorRole.Save(); } Doctor admin = ObjectSpace.FindObject <Doctor>(new BinaryOperator("UserName", "Admin")); if (admin == null) { admin = ObjectSpace.CreateObject <Doctor>(); admin.UserName = "******"; admin.SetPassword(""); admin.DoctorRoles.Add(adminDoctorRole); } else { admin.DoctorRoles.Add(adminDoctorRole); admin.SetPassword("p@ssworD"); } Doctor dvp = ObjectSpace.FindObject <Doctor>(new BinaryOperator("UserName", "dvp")); if (dvp == null) { dvp = ObjectSpace.CreateObject <Doctor>(); dvp.UserName = "******"; dvp.SetPassword(""); dvp.DoctorRoles.Add(adminDoctorRole); } /* * * var doctors = ObjectSpace.GetObjects<Doctor>().Cast<Doctor>().ToList(); * int i = 0; * foreach (var doctor in doctors) * { * if (doctor.UserName.Equals("Admin") == false) * { * doctor.IsActive = false; * doctor.ChangePasswordOnFirstLogon = true; * doctor.UserName = "******" + doctor.InnerCode.ToString(); * if (doctor.UserName.Equals("")) * { * doctor.UserName = string.Format("User{0}", i++); * } * } * }*/ /* * SecuritySystemUser sampleUser = ObjectSpace.FindObject<SecuritySystemUser>(new BinaryOperator("UserName", "User")); * if (sampleUser == null) * { * sampleUser = ObjectSpace.CreateObject<SecuritySystemUser>(); * sampleUser.UserName = "******"; * sampleUser.SetPassword(""); * } * SecuritySystemRole defaultRole = CreateDefaultRole(); * sampleUser.Roles.Add(defaultRole); * * SecuritySystemUser userAdmin = ObjectSpace.FindObject<SecuritySystemUser>(new BinaryOperator("UserName", "Admin")); * if (userAdmin == null) * { * userAdmin = ObjectSpace.CreateObject<SecuritySystemUser>(); * userAdmin.UserName = "******"; * // Set a password if the standard authentication type is used * userAdmin.SetPassword(""); * } * // If a role with the Administrators name doesn't exist in the database, create this role * SecuritySystemRole adminRole = ObjectSpace.FindObject<SecuritySystemRole>(new BinaryOperator("Name", "Administrators")); * if (adminRole == null) * { * adminRole = ObjectSpace.CreateObject<SecuritySystemRole>(); * adminRole.Name = "Administrators"; * } * adminRole.IsAdministrative = true; * userAdmin.Roles.Add(adminRole);*/ ObjectSpace.CommitChanges(); }
public bool MakeAdmin(int adminID, int roleID) { DoctorRole instance = new DoctorRole(); instance.DoctorID = adminID; instance.RoleID = roleID; dataBase.DoctorRole.InsertOnSubmit(instance); try { dataBase.DoctorRole.Context.SubmitChanges(); } catch { return false; } return true; }