예제 #1
0
        /// <summary>
        /// Save or update records for the table
        /// </summary>
        /// <param name="listCompanyApplicationDto">List of data to store CompanyApplication.</param>
        /// <returns>The result of processing the list.</returns>
        /// <author>Mauricio Suárez.</author>
        public List <CompanyApplicationDto> SaveCompanyApplication(List <CompanyApplicationDto> listCompanyApplicationDto)
        {
            List <CompanyApplication> listCompanyApplicationResult = new List <CompanyApplication>();

            using (SecurityManagmentEntities context = new SecurityManagmentEntities())
            {
                ObjectContext objectContext           = ((IObjectContextAdapter)context).ObjectContext;
                ObjectSet <CompanyApplication> set    = objectContext.CreateObjectSet <CompanyApplication>();
                string[] entityCompanyApplicationKeys = set.EntitySet.ElementType.KeyMembers.Select(k => k.Name).ToArray();

                bool[] resultValidateInsertOrUpdate = ConditionalQuery.ValidatePrimaryKeyValueInDto(listCompanyApplicationDto, entityCompanyApplicationKeys);

                int resultValidateInsertOrUpdateCount = resultValidateInsertOrUpdate.Count();

                int i = 0;
                foreach (CompanyApplicationDto dtoCompanyApplication in listCompanyApplicationDto)
                {
                    CompanyApplication entityCompanyApplication = Mapper.Map <CompanyApplicationDto, CompanyApplication>(dtoCompanyApplication);

                    if (resultValidateInsertOrUpdateCount > 0)
                    {
                        if (resultValidateInsertOrUpdate[i])
                        {
                            context.CompanyApplication.Attach(entityCompanyApplication);
                            context.Entry(entityCompanyApplication).State = System.Data.Entity.EntityState.Modified;
                        }
                        else
                        {
                            context.CompanyApplication.Add(entityCompanyApplication);
                        }
                    }
                    else
                    {
                        context.CompanyApplication.Add(entityCompanyApplication);
                    }

                    listCompanyApplicationResult.Add(entityCompanyApplication);
                    i++;
                }

                context.SaveChanges();
            }

            listCompanyApplicationDto = null;
            return(listCompanyApplicationResult.Select(Mapper.Map <CompanyApplication, CompanyApplicationDto>).ToList());
        }
        public List <NotificationsSettingsDto> GetUpdateNotifications(List <NotificationsSettingsDto> listFilterNotificationsSettings, bool summaryView)
        {
            using (SecurityManagmentEntities context = new SecurityManagmentEntities())//GetDataBaseContext())
            {
                List <ObjectParameter> parameters = new List <ObjectParameter> {
                    new ObjectParameter("StartDate", new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second))
                };

                parameters.AddRange(ConditionalQuery.GenerateParametersConditionalQuery(listFilterNotificationsSettings));
                string filterDate = (summaryView ? "SummaryEndDate" : "DashboardEndDate");

                return(context.NotificationsSettings
                       .Include(ConditionalQuery.GenerateIncludes(listFilterNotificationsSettings))
                       .Where("(" + ConditionalQuery.GenerateConditionalQuery(listFilterNotificationsSettings) + ") AND it." + filterDate + " >= @StartDate", parameters.ToArray()).AsParallel()
                       .Select(Mapper.Map <NotificationsSettings, NotificationsSettingsDto>).ToList());
            }
        }
예제 #3
0
        public override string ConditionalQueryPart(ConditionalQuery cond)
        {
            StringBuilder query = new StringBuilder();

            // WHERE
            if (cond.whereClause != null)
            {
                query.Append("WHERE ");
                query.Append(cond.whereClause.ToString());
                query.Append("\n");
            }

            // ORDER BY
            if (cond.orderByClause != null)
            {
                query.Append(cond.orderByClause.ToString());
                query.Append("\n");
            }

            // OFFSET
            if (cond is SelectQuery &&
                (cond.limit > 0 || (cond as SelectQuery).offset > 0))
            {
                /*
                 * An offset requires SQL Server 2012+
                 */
                if (cond.orderByClause == null)
                {
                    query.Append("ORDER BY (SELECT 0)\n");
                }


                SelectQuery sel = cond as SelectQuery;

                query.AppendFormat("OFFSET {0} ROWS\n", sel.offset);

                // LIMIT
                if (cond.limit > 0)
                {
                    query.AppendFormat("FETCH NEXT {0} ROWS ONLY\n", cond.limit);
                }
            }

            return(query.ToString());
        }
예제 #4
0
        /// <summary>
        /// Save or update records for the table
        /// </summary>
        /// <param name="listDataApplication">List of data to store Application.</param>
        /// <returns>The result of processing the list.</returns>
        /// <author>Mauricio Suárez.</author>
        public bool SaveApplication(List <ApplicationDto> listApplicationDto)
        {
            using (SecurityManagmentEntities context = new SecurityManagmentEntities())
            {
                ObjectContext           objectContext = ((IObjectContextAdapter)context).ObjectContext;
                ObjectSet <Application> set           = objectContext.CreateObjectSet <Application>();
                string[] entityOrderDetailKeys        = set.EntitySet.ElementType.KeyMembers.Select(k => k.Name).ToArray();

                bool[] resultValidateInsertOrUpdate = ConditionalQuery.ValidatePrimaryKeyValueInDto(listApplicationDto, entityOrderDetailKeys);

                int resultValidateInsertOrUpdateCount = resultValidateInsertOrUpdate.Count();

                int i = 0;
                foreach (ApplicationDto dtoApplication in listApplicationDto)
                {
                    if (resultValidateInsertOrUpdateCount > 0)
                    {
                        Application entityOrderDetail = null;
                        if (resultValidateInsertOrUpdate[i])
                        {
                            entityOrderDetail = Mapper.Map <ApplicationDto, Application>(dtoApplication);
                            context.Entry(entityOrderDetail).State = System.Data.Entity.EntityState.Modified;
                            context.Application.Attach(entityOrderDetail);
                        }
                        else
                        {
                            context.Application.Add(Mapper.Map <ApplicationDto, Application>(dtoApplication));
                        }
                    }
                    else
                    {
                        context.Application.Add(Mapper.Map <ApplicationDto, Application>(dtoApplication));
                    }
                    i++;
                }

                context.SaveChanges();
            }

            return(true);
        }
예제 #5
0
        /// <summary>
        /// Gets list object of the table Application.
        /// </summary>
        /// <param name="paginationDto">Attributes to apply the pagination.</param>
        /// <param name="listFilterGeneric">List that contains the DTOs from Application table that filter the query.</param>
        /// <returns>List object of the table Application.</returns>
        /// <author>Mauricio Suárez.</author>
        private List <ApplicationDto> ExecutePaginated(PaginationDto paginationDto, List <ApplicationDto> listApplicationDto)
        {
            using (SecurityManagmentEntities context = new SecurityManagmentEntities())//GetDataBaseContext())
            {
                int skipRol = paginationDto.Skip;

                if (string.IsNullOrEmpty(paginationDto.SortExpression))
                {
                    paginationDto.SortExpression = "IdApplication";
                    //paginationDto.SortDirection = SortDirection.Ascending.ToString();
                }

                return(context.Application
                       .Include(ConditionalQuery.GenerateIncludes(listApplicationDto))
                       .Where(ConditionalQuery.GenerateConditionalQuery(listApplicationDto), ConditionalQuery.GenerateParametersConditionalQuery(listApplicationDto)).AsParallel()
                       .AsQueryable()
                       .OrderBy(paginationDto.SortExpression + " " + paginationDto.SortDirectionAbbreviation)
                       .Skip(skipRol)
                       .Take(paginationDto.PageSize)
                       .Select(Mapper.Map <Application, ApplicationDto>).ToList());
            }
        }
예제 #6
0
        /// <summary>
        /// Adds single, multiple and connection queries to query
        /// </summary>
        /// <typeparam name="TModelType">The GraphQL type for returning data</typeparam>
        /// <typeparam name="TModel">The EF model type for querying the DB</typeparam>
        /// <param name="name">The name of the entity</param>
        public void AddModelQueryField <TModelType, TModel>(string name)
            where TModelType : ObjectGraphType <TModel>
            where TModel : class, IOwnerAbstractModel, new()
        {
            AddQueryField(
                $"{name}s",
                QueryHelpers.CreateResolveFunction <TModel>(),
                typeof(TModelType)).Description = $"Query for fetching multiple {name}s";

            AddSingleField(
                name: name,
                resolve: QueryHelpers.CreateResolveFunction <TModel>(),
                graphType: typeof(TModelType)).Description = $"Query for fetching a single {name}";

            AddQueryConnectionField(
                $"{name}sConnection",
                QueryHelpers.CreateResolveFunction <TModel>(),
                typeof(TModelType));

            FieldAsync <NumberObjectType>(
                $"count{name}s",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "id"
            },
                    new QueryArgument <ListGraphType <IdGraphType> > {
                Name = "ids"
            },
                    new QueryArgument <ListGraphType <WhereExpressionGraph> >
            {
                Name        = "where",
                Description = WhereDesc
            }
                    ),
                resolve: CountQuery.CreateCountQuery <TModel>(),
                description: "Counts the number of models according to a given set of conditions"
                );

            AddQueryField(
                $"{name}sConditional",
                ConditionalQuery.CreateConditionalQuery <TModel>(),
                typeof(TModelType),
                new QueryArguments(
                    new QueryArgument <ListGraphType <ListGraphType <WhereExpressionGraph> > >
            {
                Name        = "conditions",
                Description = ConditionalWhereDesc
            }
                    )
                );

            FieldAsync <NumberObjectType>(
                $"count{name}sConditional",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "id"
            },
                    new QueryArgument <ListGraphType <IdGraphType> > {
                Name = "ids"
            },
                    new QueryArgument <ListGraphType <ListGraphType <WhereExpressionGraph> > >
            {
                Name        = "conditions",
                Description = ConditionalWhereDesc
            }
                    ),
                resolve: CountQuery.CreateConditionalCountQuery <TModel>(),
                description: "Counts the number of models according to a given set of conditions. This query can " +
                "perform both AND and OR conditions"
                );
        }
예제 #7
0
        public List <ApplicationDto> GetApplicationByUser(List <ApplicationUserRoleDto> listApplicationUserRoleDto)
        {
            using (SecurityManagmentEntities context = new SecurityManagmentEntities())//GetDataBaseContext())
            {
                var predicate = ConditionalQuery.GeneratePredicateQuery <ApplicationUserRole, ApplicationUserRoleDto>(listApplicationUserRoleDto);

                return((List <ApplicationDto>)UtilitiesObject.RemoveOtherObjects(context.ApplicationUserRole
                                                                                 .Include(ConditionalQuery.GenerateIncludes(listApplicationUserRoleDto)).AsExpandable()
                                                                                 .Where(predicate).AsParallel()
                                                                                 .Select(data => data.ApplicationRole.Application)
                                                                                 .Distinct()
                                                                                 .Select(Mapper.Map <Application, ApplicationDto>).ToList()));
            }
        }