Exemple #1
0
        private Dictionary <int, int> ProccessEmployees(TermSearchModel model, List <TermViewModel> result,
                                                        List <Contracts.Entities.Terms> terms)
        {
            int columnIndex   = 0;
            var columnIndexes = new Dictionary <int, int>();

            foreach (var employee in terms.SelectMany(o => o.TermEmployees.Where(e => !e.DeleteDate.HasValue)).
                     Select(o => o.Employees).Distinct().ToList())
            {
                columnIndexes[employee.Id] = columnIndex;
                columnIndex++;

                result.Add(new TermViewModel()
                {
                    start       = model.StartDate.ToString("yyyy-MM-ddTHH:mm"),
                    end         = model.StartDate.ToString("yyyy-MM-ddTHH:mm"),
                    url         = String.Empty,
                    title       = String.Format("{0} {1}", employee.Name, employee.FirstName),
                    color       = employee.Color,
                    agendaEvent = true
                });
            }

            return(columnIndexes);
        }
Exemple #2
0
        private void ProccessAbsences(TermSearchModel model, List <TermViewModel> result, Dictionary <int, int> columnIndexes)
        {
            var absences = absencesManager.GetEntities().Where(r =>
                                                               (r.FromDate >= model.StartDate.Date && r.FromDate <= model.EndDate.Date) ||       //from date inside period
                                                               (r.ToDate >= model.StartDate.Date && r.ToDate <= model.EndDate.Date) ||           // to date inside period
                                                               (r.FromDate <= model.StartDate.Date && r.ToDate >= model.EndDate.Date)).ToList(); //period is a part of an existing one


            var columnIndex = 0;

            if (columnIndexes.Count > 0)
            {
                columnIndex = columnIndexes.Values.Max() + 1;
            }

            foreach (var employee in absences.Select(o => o.Employees).Distinct().ToList())
            {
                columnIndexes[employee.Id] = columnIndex;
                columnIndex++;

                result.Add(new TermViewModel()
                {
                    start       = model.StartDate.ToString("yyyy-MM-ddTHH:mm"),
                    end         = model.StartDate.ToString("yyyy-MM-ddTHH:mm"),
                    url         = String.Empty,
                    title       = String.Format("{0} {1}", employee.Name, employee.FirstName),
                    color       = employee.Color,
                    agendaEvent = true
                });
            }

            foreach (var absence in absences)
            {
                result.Add(new TermViewModel()
                {
                    id    = absence.Id,
                    start = new DateTime(absence.FromDate.Year, absence.FromDate.Month, absence.FromDate.Day, 7, 0, 0).ToString("yyyy-MM-ddTHH:mm"),
                    end   = new DateTime(absence.ToDate.Year, absence.ToDate.Month, absence.ToDate.Day, 18, 0, 0).ToString("yyyy-MM-ddTHH:mm"),
                    url   = "javascript:void(0)",
                    title = String.Format("{0}\n{1}",
                                          String.Format("{0} {1}", absence.Employees.Name, absence.Employees.FirstName),
                                          absence.Description),
                    address     = String.Empty,
                    color       = absence.Employees.Color,
                    agendaEvent = false,
                    columnIndex = columnIndexes[absence.EmployeeId],
                    employees   = new List <int>()
                    {
                        absence.EmployeeId
                    },
                });
            }
        }
        public IHttpActionResult Post(TermSearchModel model)
        {
            var result = new List<TermViewModel>();

            if (!String.IsNullOrEmpty(model.StartDateStr) && !String.IsNullOrEmpty(model.EndDateStr))
            {
                var terms = manager.GetActualTerms(model.StartDate, model.EndDate).ToList();
                var columnIndexes = ProccessEmployees(model, result, terms);

                ProccessTerms(result, terms, columnIndexes);

                ProccessAbsences(model, result, columnIndexes);
            }

            return Ok(result);
        }
Exemple #4
0
        public IHttpActionResult Post(TermSearchModel model)
        {
            var result = new List <TermViewModel>();

            if (!String.IsNullOrEmpty(model.StartDateStr) && !String.IsNullOrEmpty(model.EndDateStr))
            {
                var terms         = manager.GetActualTerms(model.StartDate, model.EndDate).ToList();
                var columnIndexes = ProccessEmployees(model, result, terms);

                ProccessTerms(result, terms, columnIndexes);

                ProccessAbsences(model, result, columnIndexes);
            }

            return(Ok(result));
        }
        private Dictionary<int, int> ProccessEmployees(TermSearchModel model, List<TermViewModel> result, 
            List<Contracts.Entities.Terms> terms)
        {
            int columnIndex = 0;
            var columnIndexes = new Dictionary<int, int>();

            foreach (var employee in terms.SelectMany(o => o.TermEmployees.Where(e => !e.DeleteDate.HasValue)).
                                Select(o => o.Employees).Distinct().ToList())
            {
                columnIndexes[employee.Id] = columnIndex;
                columnIndex++;

                result.Add(new TermViewModel()
                {
                    start = model.StartDate.ToString("yyyy-MM-ddTHH:mm"),
                    end = model.StartDate.ToString("yyyy-MM-ddTHH:mm"),
                    url = String.Empty,
                    title = String.Format("{0} {1}", employee.Name, employee.FirstName),
                    color = employee.Color,
                    agendaEvent = true
                });
            }

            return columnIndexes;
        }
        private void ProccessAbsences(TermSearchModel model, List<TermViewModel> result, Dictionary<int, int> columnIndexes)
        {
            var absences = absencesManager.GetEntities().Where(r =>
                   (r.FromDate >= model.StartDate.Date && r.FromDate <= model.EndDate.Date) || //from date inside period
                   (r.ToDate >= model.StartDate.Date && r.ToDate <= model.EndDate.Date) || // to date inside period
                   (r.FromDate <= model.StartDate.Date && r.ToDate >= model.EndDate.Date)).ToList();//period is a part of an existing one


            var columnIndex = 0;
            if(columnIndexes.Count > 0)
            {
                columnIndex = columnIndexes.Values.Max() + 1;
            }

            foreach (var employee in absences.Select(o => o.Employees).Distinct().ToList())
            {
                columnIndexes[employee.Id] = columnIndex;
                columnIndex++;

                result.Add(new TermViewModel()
                {
                    start = model.StartDate.ToString("yyyy-MM-ddTHH:mm"),
                    end = model.StartDate.ToString("yyyy-MM-ddTHH:mm"),
                    url = String.Empty,
                    title = String.Format("{0} {1}", employee.Name, employee.FirstName),
                    color = employee.Color,
                    agendaEvent = true
                });
            }

            foreach (var absence in absences)
            {
                result.Add(new TermViewModel()
                {
                    id = absence.Id,
                    start = new DateTime(absence.FromDate.Year, absence.FromDate.Month, absence.FromDate.Day, 7, 0, 0).ToString("yyyy-MM-ddTHH:mm"),
                    end = new DateTime(absence.ToDate.Year, absence.ToDate.Month, absence.ToDate.Day, 18, 0, 0).ToString("yyyy-MM-ddTHH:mm"),
                    url = "javascript:void(0)",
                    title = String.Format("{0}\n{1}",
                         String.Format("{0} {1}", absence.Employees.Name, absence.Employees.FirstName),
                         absence.Description),
                    address = String.Empty,
                    color = absence.Employees.Color,
                    agendaEvent = false,
                    columnIndex = columnIndexes[absence.EmployeeId],
                    employees = new List<int>() { absence.EmployeeId },
                });
            }
        }