Пример #1
0
        public async Task <IHttpActionResult> AllPCs(BootGridRequest bootRequest)
        {
            //get all pcs with it's properties
            var pcs = _pcService.AllIncluding(item => item.CPU, item => item.Motherboard, item => item.PCMemories, item => item.PowerSupply, item => item.PCMemories.Select(e => e.Memory)).ToList()
                      .Select(item => new PCBootGridModel
            {
                Id             = item.Id,
                CustomerName   = item.CustomerName,
                Motherboard    = item.Motherboard.Name,
                MemoryAmount   = item.PCMemories.Sum(pcm => pcm.Memory.Size * pcm.Count),//get sum of memory size
                PowerSupply    = item.PowerSupply.Name,
                AssemblyNeeded = item.AssemblyNeeded,
                TotalPrice     = item.TotalPrice
            })
                      .Skip((bootRequest.current - 1) * bootRequest.rowCount) //skip the previous page
                      .Take(bootRequest.rowCount);                            //take number of items
            //setup bootgrid model
            var model = new BootGridResponse <PCBootGridModel>()
            {
                Current  = bootRequest.current,
                RowCount = bootRequest.rowCount,
                Rows     = pcs,
                Total    = _pcService.All.Count()
            };

            return(Ok(model));
        }
Пример #2
0
        public JsonResult GetCustomers(BootGridRequest request)
        {
            var cusotmersVm = Mapper.Map <IEnumerable <CustomerViewModel> >(_customerService.All);
            var response    = new BootGridResponse <CustomerViewModel>(request, cusotmersVm);

            foreach (var item in response.Rows)
            {
                item.NewAssignmentCount = _assignmentService.All.Count(a => a.StatusId == 2 && a.CustomerId == item.Id);
            }
            return(Json(response));
        }
Пример #3
0
        public async Task <JsonResult> SearchInvoices(BootGridRequest request)
        {
            var invoicesVm = await SearchInvoices(request.Params);

            var response = new BootGridResponse <InvoiceViewModel>(request, invoicesVm);

            foreach (var item in response.Rows)
            {
                item.WaitingDays = item.CheckDate.HasValue ? (item.CheckDate - item.Date).Value.Days : (DateTime.Now - item.Date).Value.Days;
            }
            return(Json(response));
        }
Пример #4
0
        public string Grid(BootGridRequest bootgridRequest)
        {
            BootGridResponse bootGridResponse = new BootGridResponse();
            var alunos = _alunoService.ObterTodos();

            bootGridResponse.current  = bootgridRequest.current;
            bootGridResponse.rowCount = bootgridRequest.rowCount;

            if (!String.IsNullOrEmpty(bootgridRequest.searchphrase))
            {
                alunos = alunos.Where(a =>
                                      a.Nome.Contains(bootgridRequest.searchphrase) ||
                                      a.Cpf.Contains(bootgridRequest.searchphrase) ||
                                      a.Telefone.Contains(bootgridRequest.searchphrase));
            }

            if (bootgridRequest.sort != null && bootgridRequest.sort.Any())
            {
                switch (bootgridRequest.sort.First().Key)
                {
                case "Codigo":
                    alunos = alunos.OrderBy("Id" + " " + bootgridRequest.sort.First().Value);
                    break;

                case "Nome":
                    alunos = alunos.OrderBy("Nome" + " " + bootgridRequest.sort.First().Value);
                    break;

                case "Cpf":
                    alunos = alunos.OrderBy("Cpf" + " " + bootgridRequest.sort.First().Value);
                    break;

                case "Telefone":
                    alunos = alunos.OrderBy("Telefone" + " " + bootgridRequest.sort.First().Value);
                    break;
                }
            }
            else
            {
                alunos = alunos.OrderBy(c => c.Id);
            }


            var filtrado = alunos.ToList();

            var sqv = filtrado.Skip((bootgridRequest.current - 1) * bootgridRequest.rowCount)
                      .Take(bootgridRequest.rowCount).Select(AutoMapper.Mapper.Map <GridAlunoViewModel>).ToList();

            bootGridResponse.rows  = sqv;
            bootGridResponse.total = filtrado.Count;
            return(JsonConvert.SerializeObject(bootGridResponse));
        }
Пример #5
0
        public async Task <IHttpActionResult> AllPCs(BootGridRequest bootRequest)
        {
            //get all pcs with it's properties
            var pcs = _pcService.AllIncluding(item => item.CPU, item => item.Motherboard, item => item.PCMemories,
                                              item => item.PowerSupply, item => item.PCMemories.Select(e => e.Memory))
                      .Select(item => new PCBootGridModel
            {
                Id             = item.Id,
                CustomerName   = item.CustomerName,
                Motherboard    = item.Motherboard.Name,
                MemoryAmount   = item.PCMemories.Sum(pcm => pcm.Memory.Size * pcm.Count), //get sum of memory size
                PowerSupply    = item.PowerSupply.Name,
                AssemblyNeeded = item.AssemblyNeeded,
                TotalPrice     = item.TotalPrice
            });

            //setup bootgrid model
            var model = new BootGridResponse <PCBootGridModel>(bootRequest, pcs);

            return(Ok(model));
        }
Пример #6
0
        public async Task <JsonResult> GetInvoices(BootGridRequest request)
        {
            var isAdmin = User.IsInRole("admin");

            if (isAdmin && !request.Params.ContainsKey("assignmentId"))
            {
                return(await SearchInvoices(request));
            }
            int?assignmentId = null;

            if (request.Params != null && request.Params.Keys.Contains("assignmentId") && !string.IsNullOrEmpty(request.Params["assignmentId"]))
            {
                assignmentId = int.Parse(request.Params["assignmentId"]);
            }
            var invoicesVm = Mapper.Map <IEnumerable <InvoiceViewModel> >(_invoiceService.AllIncluding(item => item.Assignment, item => item.InvoiceStatus, item => item.Assignment.AssignmentStatus).Where(item => (item.Assignment.CustomerId == CustomerId || isAdmin) && (!assignmentId.HasValue || item.AssignmentId == assignmentId.Value)));
            var response   = new BootGridResponse <InvoiceViewModel>(request, invoicesVm);

            foreach (var item in response.Rows)
            {
                item.FilesCount = _invoiceAttachmentService.All.Count(ia => ia.InvoiceId == item.Id);
            }
            return(Json(response));
        }
Пример #7
0
        public JsonResult GetAssignments(BootGridRequest request)
        {
            int?statusId = null;

            if (request.Params != null)
            {
                if (request.Params.Keys.Contains("StatusId") && !string.IsNullOrEmpty(request.Params["StatusId"]))
                {
                    statusId = int.Parse(request.Params["StatusId"]);
                }
            }

            var isAdmin       = User.IsInRole("admin");
            var assignmentsVm = Mapper.Map <IEnumerable <AssignmentViewModel> >(_assignmentService.AllIncluding(item => item.AssignmentStatus).Where(item => (item.CustomerId == CustomerId || isAdmin) && (!statusId.HasValue || item.StatusId == statusId.Value) && ((!isAdmin || item.StatusId > 2))));
            var response      = new BootGridResponse <AssignmentViewModel>(request, assignmentsVm);

            foreach (var item in response.Rows)
            {
                item.InvoicesCount = _invoiceService.All.Count(i => i.AssignmentId == item.Id);
                item.Adjustment    = _overpaymentService.FindBy(e => e.OriginInvoice.AssignmentId == item.Id && e.StatusId == 1).Sum(e => (decimal?)e.Amount);
            }
            return(Json(response));
        }
Пример #8
0
        public JsonResult GetAdjustments(BootGridRequest request)
        {
            int?customerId   = null;
            int?assignmentId = null;

            if (request.Params != null)
            {
                if (request.Params.Keys.Contains("CustomerId") && !string.IsNullOrEmpty(request.Params["CustomerId"]))
                {
                    customerId = int.Parse(request.Params["CustomerId"]);
                }
                if (request.Params.Keys.Contains("AssignmentId") && !string.IsNullOrEmpty(request.Params["AssignmentId"]))
                {
                    assignmentId = int.Parse(request.Params["AssignmentId"]);
                }
            }
            var adjustmentsVm =
                Mapper.Map <IEnumerable <AdjustmentViewModel> >(
                    _adjustmentService.AllIncluding(item => item.OriginInvoice, item => item.OriginInvoice.Assignment)
                    .Where(item => (!customerId.HasValue || item.CustomerId == customerId) && (item.StatusId == 1 || item.AppliedAssignmentId == assignmentId)));
            var response = new BootGridResponse <AdjustmentViewModel>(request, adjustmentsVm);

            return(Json(response));
        }
Пример #9
0
        public JsonResult GetUsers(BootGridRequest request)
        {
            var usersVm = Mapper.Map <IEnumerable <UserViewModel> >(UserManager.Users.Include(item => item.Customer));

            return(Json(new BootGridResponse <UserViewModel>(request, usersVm)));
        }