Пример #1
0
        public LInst.User CreateNewUser(Person personInstance,
                                        string userName,
                                        string password)
        {
            LInst.User output = new LInst.User();
            output.FullName       = "";
            output.UserName       = userName;
            output.HashedPassword = CalculateHash(password, userName);
            using (LInstContext context = _contextFactory.CreateDbContext(new string[] { }))
            {
                output.Person = context.People.First(per => per.ID == personInstance.ID);
                foreach (UserRole role in context.UserRoles)
                {
                    UserRoleMapping tempMapping = new UserRoleMapping();
                    tempMapping.UserRole   = role;
                    tempMapping.IsSelected = false;

                    output.RoleMappings.Add(tempMapping);
                }
                context.Users.Add(output);
                context.SaveChanges();
            }

            return(output);
        }
Пример #2
0
        public void AddOrganizationRole(string name)
        {
            using (LInstContext entities = _dbContextFactory.CreateDbContext(new string[] { }))
            {
                OrganizationRole newRole = new OrganizationRole
                {
                    Name        = name,
                    Description = ""
                };

                entities.OrganizationRoles.Add(newRole);

                foreach (Organization org in entities.Organizations)
                {
                    OrganizationRoleMapping newMapping = new OrganizationRoleMapping
                    {
                        OrganizationRole = newRole,
                        Organization     = org,
                        IsSelected       = false
                    };
                    entities.OrganizationRoleMappings.Add(newMapping);
                }

                entities.SaveChanges();
            }
        }
Пример #3
0
        public IEnumerable <Instrument> GetCalibrationCalendar()
        {
            // Returns a list of the instruments under control, ordered by due calibration date

            using (LInstContext entities = _dbContextFactory.CreateDbContext(new string[] { }))
            {
                return(entities.Instruments.Include(ins => ins.InstrumentType)
                       .Include(ins => ins.UtilizationArea)
                       .Include(ins => ins.CalibrationResponsible)
                       .Where(ins => ins.IsUnderControl == true)
                       .OrderBy(ins => ins.CalibrationDueDate)
                       .ToList());
            }
        }
Пример #4
0
 /// <summary>
 /// Retrieves and returns the next available CalibrationReport number for a given year
 /// </summary>
 /// <param name="year">The year on which the query is performed</param>
 /// <returns>The first unused calibration number</returns>
 public int GetNextCalibrationNumber(int year)
 {
     using (LInstContext entities = _dbContextFactory.CreateDbContext(new string[] { }))
     {
         try
         {
             return(entities.CalibrationReports
                    .Where(crep => crep.Year == year)
                    .Max(crep => crep.Number) + 1);
         }
         catch
         {
             return(1);
         }
     }
 }
Пример #5
0
        /// <summary>
        /// Creates and inserts in the DB the mappings between a new OrganizationRole
        /// and all the existing organization
        /// </summary>
        /// <param name="newRole">The role for which will be built the mappings</param>
        internal void CreateMappingsForNewRole(OrganizationRole newRole)
        {
            using (LInstContext entities = _dbContextFactory.CreateDbContext(new string[] { }))
            {
                IEnumerable <Organization> _orgList = entities.Organizations.ToList();

                foreach (Organization org in _orgList)
                {
                    OrganizationRoleMapping tempMap = new OrganizationRoleMapping()
                    {
                        IsSelected         = false,
                        OrganizationRoleID = newRole.ID
                    };

                    org.RoleMappings.Add(tempMap);
                }

                entities.SaveChanges();
            }
        }
Пример #6
0
        public PersonRole CreateNewPersonRole()
        {
            StringInputDialog addPersonRoleDialog = new StringInputDialog();

            addPersonRoleDialog.Title   = "Creazione nuovo Ruolo Persona";
            addPersonRoleDialog.Message = "Nome:";

            if (addPersonRoleDialog.ShowDialog() != true)
            {
                return(null);
            }

            PersonRole newRole = new PersonRole
            {
                Name        = addPersonRoleDialog.InputString,
                Description = ""
            };

            using (LInstContext entities = _dbContextFactory.CreateDbContext(new string[] { }))
            {
                entities.PersonRoles.Add(newRole);

                foreach (Person per in entities.People)
                {
                    PersonRoleMapping newMapping = new PersonRoleMapping
                    {
                        Person     = per,
                        IsSelected = false
                    };
                    newRole.RoleMappings.Add(newMapping);
                }

                entities.SaveChanges();
            }

            return(newRole);
        }