Exemplo n.º 1
0
 public void DbTest1()
 {
     using (BioDivContext db = new BioDivContext())
     {
         var allGeometries = db.Geometries.ToList();
     }
     Assert.Pass();
 }
Exemplo n.º 2
0
        protected override ValidationResult IsValid(object value, ValidationContext context)
        {
            BioDivContext db = (BioDivContext)context.GetService(typeof(BioDivContext));

            if (db.Groups.Where(m => m.GroupName == value.ToString()).Any())
            {
                return(new ValidationResult("Dieser Gruppenname wird bereits verwendet. Bitte einen anderen Gruppennamen wählen"));
            }
            return(ValidationResult.Success);
        }
Exemplo n.º 3
0
        public static User GetCurrentUser(ClaimsPrincipal userClaims, BioDivContext db)
        {
            ClaimsIdentity identity = (ClaimsIdentity)userClaims.Identity;
            string         username = identity.FindFirst("preferred_username").Value;
            User           u        = db.Users.Find(username);

            if (u != null)
            {
                return(u);
            }


            return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// get projects for given user depending on his role
        /// </summary>
        /// <param name="db"></param>
        /// <param name="user"></param>
        /// <param name="role"></param>
        /// <returns>
        /// List(projects) with undeleted projets
        /// </returns>
        public async static Task <List <Project> > UserProjectsAsync(BioDivContext db, User user, RoleEnum role)
        {
            if (db == null)
            {
                throw new ArgumentNullException(nameof(db));
            }
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            string userName = user.UserId;

            IQueryable <Project> projectsQuery = db.Projects
                                                 .Include(p => p.ProjectConfigurator)
                                                 .Include(p => p.ProjectManager)
                                                 .Where(p => p.StatusId != StatusEnum.deleted) //only active pojects
            ;

            switch (role)
            {
            case RoleEnum.BE:
                throw new NotImplementedException();
                break;

            case RoleEnum.AV:
                throw new NotImplementedException();
                break;

            case RoleEnum.DH:
                throw new NotImplementedException();
                break;

            case RoleEnum.DM:
                //not changing query
                break;

            case RoleEnum.PL:
                projectsQuery = projectsQuery.Where(p => p.ProjectManager.UserId == userName);
                break;

            case RoleEnum.PK:
                projectsQuery = projectsQuery.Where(p => p.ProjectConfigurator.UserId == userName);
                break;

            case RoleEnum.EF:
                projectsQuery = db.GroupsUsers
                                .Where(gu => gu.UserId == userName)
                                .Include(gu => gu.Group)
                                .ThenInclude(g => g.GroupProjects)
                                .ThenInclude(gp => gp.Project.ProjectManager)
                                .Include(gu => gu.Group)
                                .ThenInclude(g => g.GroupProjects)
                                .ThenInclude(gp => gp.Project.ProjectConfigurator)
                                .Select(gu => gu.Group)
                                .Where(g => g.StatusId != StatusEnum.deleted)                                                                                          //only active groups
                                                                                                                                                                       // .Where(g => g.GroupStatusId == GroupStatusEnum.Gruppe_bereit ||
                                                                                                                                                                       //       g.GroupStatusId == GroupStatusEnum.Gruppendaten_fehlerhaft)      // 20210109 chs: change to GroupProjects below
                                .SelectMany(g => g.GroupProjects).Where(gp => gp.GroupStatusId == GroupStatusEnum.Gruppe_bereit ||
                                                                        gp.GroupStatusId == GroupStatusEnum.Gruppendaten_fehlerhaft).Where(gp => gp.ReadOnly == false) //only ready and faulty groups
                                .Select(gp => gp.Project)
                                .Where(p => p.StatusId != StatusEnum.deleted)                                                                                          //only active pojects
                                .Where(p => p.ProjectStatusId == ProjectStatusEnum.Projekt_bereit);                                                                    //only ready projects
                break;

            case RoleEnum.LE:
                projectsQuery = db.GroupsUsers
                                .Where(gu => gu.UserId == userName)
                                .Include(gu => gu.Group)
                                .ThenInclude(g => g.GroupProjects)
                                .ThenInclude(gp => gp.Project.ProjectManager)
                                .Include(gu => gu.Group)
                                .ThenInclude(g => g.GroupProjects)
                                .ThenInclude(gp => gp.Project.ProjectConfigurator)
                                .Select(gu => gu.Group)
                                .Where(g => g.StatusId != StatusEnum.deleted) //only active groups
                                                                              //.Where(g => g.GroupStatusId == GroupStatusEnum.Gruppe_bereit ||
                                                                              //       g.GroupStatusId == GroupStatusEnum.Gruppendaten_fehlerhaft || g.GroupStatusId == GroupStatusEnum.Gruppendaten_gueltig)      //only ready and faulty groups and gueltig (readonlys are gueltig)
                                                                              // 20210109 chs: change to GroupProjects below
                                .SelectMany(g => g.GroupProjects).Where(gp => gp.ReadOnly == true ||
                                                                        gp.GroupStatusId == GroupStatusEnum.Gruppendaten_fehlerhaft || gp.GroupStatusId == GroupStatusEnum.Gruppendaten_gueltig ||
                                                                        gp.GroupStatusId == GroupStatusEnum.Gruppendaten_erfasst)
                                .Select(gp => gp.Project)
                                .Where(p => p.StatusId != StatusEnum.deleted)                       //only active pojects
                                .Where(p => p.ProjectStatusId == ProjectStatusEnum.Projekt_bereit); //only ready projects
                break;

            case RoleEnum.LE_OGD:
                projectsQuery = projectsQuery.Where(p => p.OGD == true);
                break;

            case RoleEnum.NZ:
                throw new NotImplementedException();
                break;

            default:
                throw new NotImplementedException();
                break;
            }

            return(await projectsQuery.Distinct().ToListAsync());
        }
Exemplo n.º 5
0
 public UptimeController(BioDivContext context, ILogger <ProjectController> logger)
 {
     _context = context;
     _logger  = logger;
 }
        public static async Task CreateDynamicView(BioDivContext db, ReferenceGeometry rg, ProjectGroup g, List <Group> myGroups, GeometrieViewModel gvm)
        {
            foreach (Record r in rg.Records.Where(m => m.StatusId != StatusEnum.deleted))
            {
                bool isReadOnly = true;
                if (g == null)
                {
                    isReadOnly = false;
                }
                else if ((g.GroupStatusId != GroupStatusEnum.Gruppendaten_gueltig) && (g.GroupStatusId != GroupStatusEnum.Gruppendaten_erfasst))
                {
                    if (myGroups.Where(m => m.GroupId == r.ProjectGroupGroupId).Count() > 0)
                    {
                        isReadOnly = false;
                    }
                }

                RecordViewModel rvm = new RecordViewModel()
                {
                    Record = r
                };

                List <PropertyVm> dynamicForm = new List <PropertyVm>();

                // BDC Guid
                PropertyVm dynamicFieldGUID = new PropertyVm(typeof(string), "Field_" + r.RecordId);
                dynamicFieldGUID.DisplayName         = "BDCGuid";
                dynamicFieldGUID.Value               = r.BDCGuid;
                dynamicFieldGUID.GetCustomAttributes = () => new object[] { new Helpers.FormFactory.GuidAttribute() };
                dynamicForm.Add(dynamicFieldGUID);

                if (r.Form != null)
                {
                    foreach (FormField ff in r.Form.FormFormFields.Select(fff => fff.FormField).OrderBy(m => m.Order))
                    {
                        FormField origFormField = ff;
                        if (ff.PublicMotherFormField != null)
                        {
                            origFormField = ff.PublicMotherFormField;
                        }

                        if (origFormField.FieldTypeId == FieldTypeEnum.Text)
                        {
                            PropertyVm dynamicField = new PropertyVm(typeof(string), "Field_" + ff.FormFieldId.ToString());
                            dynamicField.DisplayName = origFormField.Title;
                            TextData td = r.TextData.Where(m => m.FormField == ff).FirstOrDefault();
                            if (td != null)
                            {
                                dynamicField.Value = td.Value;
                            }

                            dynamicField.NotOptional = ff.Mandatory;
                            dynamicForm.Add(dynamicField);
                        }
                        else if (origFormField.FieldTypeId == FieldTypeEnum.DateTime)
                        {
                            PropertyVm dynamicField = new PropertyVm(typeof(DateTime), "Field_" + ff.FormFieldId.ToString());
                            dynamicField.DisplayName = origFormField.Title;
                            TextData td   = r.TextData.Where(m => m.FormField == ff).FirstOrDefault();
                            DateTime myDT = new DateTime();
                            try
                            {
                                myDT = DateTime.ParseExact(td.Value.Replace("{0:", " ").Replace("}", ""), formats, CultureInfo.InvariantCulture, DateTimeStyles.None);
                            }
                            catch (Exception e)
                            {
                            }

                            if (td != null)
                            {
                                dynamicField.Value = myDT;
                            }

                            dynamicField.NotOptional = ff.Mandatory;
                            dynamicForm.Add(dynamicField);
                        }
                        else if (origFormField.FieldTypeId == FieldTypeEnum.Choice)
                        {
                            PropertyVm dynamicField = new PropertyVm(typeof(string), "Field_" + ff.FormFieldId.ToString());
                            dynamicField.DisplayName = origFormField.Title;
                            TextData td = r.TextData.Where(m => m.FormField == ff).FirstOrDefault();
                            if (td != null)
                            {
                                dynamicField.Value = td.Value;
                            }

                            await db.Entry(origFormField).Collection(m => m.FieldChoices).LoadAsync();

                            if (origFormField.FieldChoices != null)
                            {
                                List <string> choices = new List <string>();
                                foreach (FieldChoice fc in origFormField.FieldChoices.OrderBy(m => m.Order))
                                {
                                    choices.Add(fc.Text);
                                }
                                dynamicField.Choices = choices;
                            }
                            dynamicField.NotOptional = ff.Mandatory;
                            dynamicForm.Add(dynamicField);
                        }
                        else if (origFormField.FieldTypeId == FieldTypeEnum.Boolean)
                        {
                            PropertyVm dynamicField = new PropertyVm(typeof(bool), "Field_" + ff.FormFieldId.ToString());
                            dynamicField.DisplayName = origFormField.Title;
                            BooleanData bd = r.BooleanData.Where(m => m.FormField == ff).FirstOrDefault();
                            if (bd != null)
                            {
                                dynamicField.Value = bd.Value;
                            }
                            dynamicField.NotOptional         = ff.Mandatory;
                            dynamicField.GetCustomAttributes = () => new object[] { new FormFactory.Attributes.LabelOnRightAttribute() };
                            dynamicForm.Add(dynamicField);
                        }
                    }

                    PropertyVm dynamicHiddenField = new PropertyVm(typeof(string), "RecordId");
                    dynamicHiddenField.Value       = r.RecordId.ToString();
                    dynamicHiddenField.NotOptional = true;
                    dynamicHiddenField.IsHidden    = true;
                    dynamicForm.Add(dynamicHiddenField);

                    if (isReadOnly)
                    {
                        foreach (PropertyVm pv in dynamicForm)
                        {
                            pv.Readonly = true;
                        }
                    }
                    rvm.Readonly    = isReadOnly;
                    rvm.DynamicForm = dynamicForm;
                    rvm.Group       = r.ProjectGroup.Group;
                    gvm.Records.Add(rvm);
                }
            }

            return;
        }