Ejemplo n.º 1
0
        protected virtual void SetFilterDefaults(ProjectFilterModel filter)
        {
            if (!filter.Set.HasValue)
            {
                filter.Set = ProjectSet.All;
            }

            if (!filter.Sort.HasValue)
            {
                filter.Sort = ProjectSort.Name;
            }

            if (!filter.Order.HasValue)
            {
                filter.Order = OrderDirection.Ascending;
            }

            if (!filter.Skip.HasValue || filter.Skip.Value < 0)
            {
                filter.Skip = 0;
            }

            if (!filter.Take.HasValue || filter.Take.Value < 0)
            {
                filter.Take = DefaultTake;
            }

            if (filter.Set.Value != ProjectSet.Associated && filter.Set.Value != ProjectSet.NonAssociated)
            {
                filter.DeveloperContextUrl = "";
            }
        }
Ejemplo n.º 2
0
        public PartialViewResult FilterProjects(ProjectFilterModel filter)
        {
            if (filter.Type < 4)
            {
                filter.Type = 1;
            }

            return(PartialView("~/Views/Shared/_ProjectListPartial.cshtml", MainHelper._projects.Projects.Where(s => filter.Type == 0 || s.Type == filter.Type).ToList().Filter(filter)));
        }
Ejemplo n.º 3
0
 public static OrderModel GetOrderModel(this ProjectFilterModel filter)
 {
     return(new OrderModel
     {
         SortColumn = filter.Sort.Value.ToString(),
         isAscendingOrder = filter.Order.Value == OrderDirection.Ascending,
         Skip = filter.Skip.Value,
         Take = filter.Take.Value
     });
 }
Ejemplo n.º 4
0
        //retrive predefined sets of Projects
        protected virtual Task <IEnumerable <Project> > GetSetOrAll(ProjectFilterModel filter)
        {
            //ToDo switch statements should be omitted using polymorphism

            if (filter.Set.Value == ProjectSet.Associated)
            {
                return(Repo.GetAssignedTo(
                           devName: filter.DeveloperContextUrl,
                           status: null,
                           keywords: filter.Keywords,
                           order: filter.GetOrderModel()));
            }

            if (filter.Set.Value == ProjectSet.NonAssociated)
            {
                return(Repo.GetAssignableTo(
                           devName: filter.DeveloperContextUrl,
                           status: null,
                           keywords: filter.Keywords,
                           order: filter.GetOrderModel()));
            }

            if (filter.Set.Value == ProjectSet.Completed)
            {
                return(Repo.GetByStatus(
                           status: ProjectStatus.Completed,
                           keywords: filter.Keywords,
                           order: filter.GetOrderModel()));
            }

            if (filter.Set.Value == ProjectSet.UnStarted)
            {
                return(Repo.GetByStatus(
                           status: ProjectStatus.UnStarted,
                           keywords: filter.Keywords,
                           order: filter.GetOrderModel()));
            }

            if (filter.Set.Value == ProjectSet.Active)
            {
                return(Repo.GetByStatus(
                           status: ProjectStatus.InProgress,
                           keywords: filter.Keywords,
                           order: filter.GetOrderModel()));
            }

            return(Repo.Get(filter.Keywords, filter.GetOrderModel()));
        }
Ejemplo n.º 5
0
        //ToDO
        private async Task <bool> ValidateFilter(ProjectFilterModel filter)
        {
            //if retriving associated data (devs of project) and context not given or project does't exist
            if (filter.Set.Value == ProjectSet.Associated || filter.Set.Value == ProjectSet.NonAssociated)
            {
                if (string.IsNullOrEmpty(filter.DeveloperContextUrl))
                {
                    ModelState.AddModelError(nameof(filter.DeveloperContextUrl), string.Format("Developer url not provided in \"Context\" field", nameof(filter.DeveloperContextUrl)));
                }
                //else if (!await _mng.DeveloperExists(Decode(filter.Context)))
                //{
                //    ModelState.AddModelError(nameof(filter.Context), string.Format("Developer with nickname {0} was not found", Decode(filter.Context)));
                //}
            }

            return(ModelState.IsValid);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Get([FromQuery] ProjectFilterModel filter)
        {
            SetFilterDefaults(filter);

            if (!await ValidateFilter(filter))
            {
                return(BadRequest(ModelState.GetValidationProblemDetails()));
            }

            var projects = await GetSetOrAll(filter);

            string developerUrl = filter.Set.Value == ProjectSet.Associated ? filter.DeveloperContextUrl : "";

            return(new JsonResult(new PaginationCollection <EditProjectViewModel>()
            {
                Values = projects
                         .Select(x => x.GetVM(Encode(x.Name), developerUrl))
                         .ToArray(),
                TotalCount = Repo.LastQueryTotalCount
            }));
        }
Ejemplo n.º 7
0
        public ActionResult ProjectsList(int?type)
        {
            var model = MainHelper._projects.Projects;

            var filter = new ProjectFilterModel();

            if (type.HasValue)
            {
                filter.Type = type.Value < 4 ? 1 : type.Value;
                switch (type.Value)
                {
                case 1:
                    filter.Matherial1 = true;
                    break;

                case 2:
                    filter.Matherial2 = true;
                    break;

                case 3:
                    filter.Matherial3 = true;
                    break;
                }
                model = model.Where(s => s.Type == filter.Type).ToList().Filter(filter);
            }

            model.ForEach(s =>
            {
                s.Price = MainHelper.GetProjectCost(s.Id, type == 2 ? 2 : 1, 0);
            });

            model = model.OrderByDescending(o => o.Index).ThenBy(o => o.Area).ToList();

            ViewBag.ProjectFilter = filter;
            return(View(model));
        }
Ejemplo n.º 8
0
        private static bool FilteredProject(ProjectModel project, ProjectFilterModel filter)
        {
            if (filter.IsEmpty())
            {
                return(true);
            }

            var areaResult = false;

            if (filter.Area1 && project.Area <= 100)
            {
                areaResult = true;
            }

            if (filter.Area2 && project.Area > 100 && project.Area <= 200)
            {
                areaResult = true;
            }

            if (filter.Area3 && project.Area > 200)
            {
                areaResult = true;
            }

            if ((filter.Area1 || filter.Area2 || filter.Area3) && !areaResult)
            {
                return(false);
            }

            var matherialResult = false;

            if (filter.Matherial1 && project.Matherials.Contains(Matherial.ОЦБ))
            {
                matherialResult          = true;
                project.CurrentMatherial = Matherial.ОЦБ;
            }

            if (filter.Matherial2 && project.Matherials.Contains(Matherial.КБ))
            {
                matherialResult          = true;
                project.CurrentMatherial = Matherial.КБ;
            }

            if (filter.Matherial3 && project.Matherials.Contains(Matherial.КОМБИ))
            {
                matherialResult = true;
            }

            if ((filter.Matherial1 || filter.Matherial2 || filter.Matherial3) && !matherialResult)
            {
                return(false);
            }

            var cost        = GetProjectMinCost(project.Id);
            var priceResult = false;

            if (filter.Price1 && (cost <= 1000000 || cost == 0))
            {
                priceResult = true;
            }

            if (filter.Price2 && (cost == 0 || (cost > 1000000 && cost <= 2000000)))
            {
                priceResult = true;
            }

            if (filter.Price3 && (cost > 2000000 || cost == 0))
            {
                priceResult = true;
            }

            if ((filter.Price1 || filter.Price2 || filter.Price3) && !priceResult)
            {
                return(false);
            }

            var floorResult = false;

            if (filter.Floor1 && project.FloorsCount == 1)
            {
                floorResult = true;
            }

            if (filter.Floor2 && project.FloorsCount == 2)
            {
                floorResult = true;
            }

            if (filter.Floor3 && project.FloorsCount > 2)
            {
                floorResult = true;
            }

            if ((filter.Floor1 || filter.Floor2 || filter.Floor3) && !floorResult)
            {
                return(false);
            }

            var attributesResult = (filter.HasBalcony && project.HasBalcony) ||
                                   (filter.HasErker && project.HasErker) ||
                                   (filter.HasSecondLight && project.HasSecondLight) ||
                                   (filter.HasTerrace && project.HasTerrace);

            if ((filter.HasBalcony || filter.HasErker || filter.HasSecondLight || filter.HasTerrace) && !attributesResult)
            {
                return(false);
            }

            return(areaResult || matherialResult || priceResult || floorResult || attributesResult);
        }
Ejemplo n.º 9
0
 public static List <ProjectModel> Filter(this List <ProjectModel> list, ProjectFilterModel filter)
 {
     return(list.Where(s => FilteredProject(s, filter)).OrderBy(x => x.Index).ToList());
 }