public IActionResult Index(string searchString = "")
        {
            _logger.LogInformation($"Getting Customers' List, search by {searchString}, user: {User.Identity.Name}");
            try
            {
                _clientIndexMapper = _entityMapperContextBase.Set <Point, Client>(cfg =>
                {
                    cfg.CreateMap <Point, Client>()
                    .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.PointNumber))
                    .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.NamePoint))
                    .ForMember(dest => dest.GroupName, opt => opt.MapFrom(src => src.CliGroup.CliGroupName))
                    .ForMember(dest => dest.ContactName, opt => opt.MapFrom(src => src.ContactPerson))
                    .ForMember(dest => dest.PhoneNumber, opt => opt.MapFrom(src => src.Telefon))
                    .ForMember(dest => dest.Balance, opt => opt.MapFrom(src => src.Saldo));
                }
                                                                                  );
            }
            catch (Exception ex)
            {
                _logger.LogError($"Mapping error: {ex.Message}");
            }

            IEnumerable <Client> clients;
            var model = new ClientsIndexViewModel();

            if (!string.IsNullOrEmpty(searchString))
            {
                model.SearchString = string.Concat(searchString.ToCharArray().Where(c => !Char.IsWhiteSpace(c)));

                clients = _context.Set <Point>()
                          .GetAll()
                          //.FindBy(p => p.CliGroupNumber == 7 || p.CliGroupNumber == 2)
                          ?.Where(p => p.NamePoint.ToLower().Contains(searchString.ToLower()))
                          ?.Include(e => e.CliGroup)
                          ?.Select(c => _clientIndexMapper.Map(c))
                          ?.OrderBy(c => c.GroupName)
                          .ThenBy(c => c.Name);
            }
            else
            {
                clients = _context.Set <Point>()
                          .GetAll()
                          //?.FindBy(p => p.CliGroupNumber == 7 || p.CliGroupNumber == 2)
                          ?.Include(e => e.CliGroup)
                          ?.Select(c => _clientIndexMapper.Map(c))
                          ?.OrderBy(c => c.GroupName)
                          .ThenBy(c => c.Name);
            }
            if (clients != null)
            {
                model.Clients = clients;
                return(View(model));
            }
            else
            {
                _logger.LogWarning("Customers NOT FOUND!");
                return(NotFound("Клиенты не найдены"));
            }
        }
示例#2
0
        public TDTO Add(TDTO dto)
        {
            if (dto == null)
            {
                return(null);
            }
            var entity = _repository.Add(_entityMapper.Map(dto));

            //dto.Id=entity.
            return(dto);
        }
        public IActionResult ClientPaymentDetails(int id)
        {
            _logger.LogInformation($"Getting Customer PAYMENT DETAILS INFO, ID: {id}, user: {User.Identity.Name}");
            try
            {
                _clientPaymentDetailsMapper = _entityMapperContextBase.Set <Point, ClientPaymentDetailsEditViewModel>(cfg =>
                {
                    cfg.CreateMap <Point, ClientPaymentDetailsEditViewModel>()
                    .ForMember(dest => dest.FiscalNumber, opt => opt.MapFrom(src => src.IndNum))
                    .ForMember(dest => dest.Certificate, opt => opt.MapFrom(src => src.SvidNum));
                }
                                                                                                                      );
            }
            catch (Exception ex)
            {
                _logger.LogError($"Mapping error: {ex.Message}");
            }

            var model = _context.Set <Point>()
                        .FindBy(p => p.PointNumber == id)
                        .Select(c => _clientPaymentDetailsMapper.Map(c))
                        .FirstOrDefault();

            if (model != null)
            {
                model.Id = id;
                var contractors = _context.Set <Point>()
                                  .FindBy(p => p.Post == false)
                                  ?.Select(p => new ContractorDto
                {
                    Id   = p.PointNumber,
                    Name = p.NamePoint
                });
                if (contractors != null)
                {
                    model.Contractors = contractors.ToList();
                }
                return(PartialView(model));
            }
            else
            {
                _logger.LogWarning($"Customer with ID: {id} NOT FOUND!");
                return(NotFound($"Клиент с id: {id} не найден."));
            }
        }
        public IActionResult Edit(int id)
        {
            _logger.LogInformation($"Getting Customer, ID: {id}, user: {User.Identity.Name}");
            try
            {
                _clientEditMapper = _entityMapperContextBase.Set <Point, ClientEditViewModel>(cfg =>
                {
                    cfg.CreateMap <Point, ClientEditViewModel>()
                    .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.PointNumber))
                    .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.NamePoint));
                }
                                                                                              );
            }
            catch (Exception ex)
            {
                _logger.LogError($"Mapping error: {ex.Message}");
            }
            var model = _context.Set <Point>()
                        ?.FindBy(p => p.PointNumber == id)
                        ?.Include(p => p.CliGroup)
                        ?.Select(p => _clientEditMapper.Map(p))
                        ?.FirstOrDefault();

            if (model != null)
            {
                // Add List of Groups to the Model
                IEnumerable <CliGroup> groups = _context.Set <CliGroup>()
                                                ?.FindBy(g => g.CliGroupNumber == 2 || g.CliGroupNumber == 7);
                model.CliGroups = groups?.ToList();
                return(View(model));
            }
            else
            {
                _logger.LogWarning($"Customer with ID: {id} NOT FOUND!");
                return(NotFound($"Клиент с id: {id} не найден."));
            }
        }
        public IActionResult ClientDebtDetails(int id)
        {
            _logger.LogInformation($"Getting Customer DEBT DETAILS INFO, ID: {id}, user: {User.Identity.Name}");
            try
            {
                _clientDebtDetailsMapper = _entityMapperContextBase.Set <Point, ClientDebtDetailsEditViewModel>(cfg =>
                {
                    cfg.CreateMap <Point, ClientDebtDetailsEditViewModel>()
                    .ForMember(dest => dest.BillSettings, opt => opt.MapFrom(src => src.BillSettingsInfo))
                    .ForMember(dest => dest.DebtControl, opt => opt.MapFrom(src => src.DebtControlInfo))
                    .ForMember(dest => dest.FranchisingTypeId, opt => opt.MapFrom(src => src.FranchisingInfo.FranchisingTypeId))
                    .ForMember(dest => dest.DebtCalcMethodTypeId, opt => opt.MapFrom(src => src.DebtCalcMethodInfo.DebtCalcMethodTypeId))
                    .ForMember(dest => dest.ClientConnection, opt => opt.MapFrom(src => src.ClientConnectionInfo))
                    .ForMember(dest => dest.BillOptionsAll, opt => opt.MapFrom(src => src.BillOptionsInfo))
                    .ForMember(dest => dest.PrintJobsAll, opt => opt.MapFrom(src => src.PrintJobInfo))
                    .ForMember(dest => dest.BillSettings, opt => opt.Condition(src => src.BillSettingsInfo != null))
                    .ForMember(dest => dest.DebtControl, opt => opt.Condition(src => src.DebtControlInfo != null))
                    .ForMember(dest => dest.FranchisingTypeId, opt => opt.Condition(src => src.FranchisingInfo != null))
                    .ForMember(dest => dest.DebtCalcMethodTypeId, opt => opt.Condition(src => src.DebtCalcMethodInfo != null))
                    .ForMember(dest => dest.ClientConnection, opt => opt.Condition(src => src.ClientConnectionInfo != null))
                    .ForMember(dest => dest.BillOptionsAll, opt => opt.Condition(src => src.BillOptionsInfo != null))
                    .ForMember(dest => dest.PrintJobsAll, opt => opt.Condition(src => src.PrintJobInfo != null))
                    ;
                    cfg.CreateMap <PrintJobInfo, PrintJobDto>();
                    cfg.CreateMap <BillOptionsInfo, BillOptionsDto>();
                });
            }
            catch (Exception ex)
            {
                _logger.LogError($"Mapping error: {ex.Message}");
            }

            var clients = _context.Set <Point>()
                          ?.FindBy(p => p.PointNumber == id)
                          ?.Include(p => p.BillSettingsInfo)
                          ?.Include(p => p.BillOptionsInfo)
                          ?.Include(p => p.PrintJobInfo)
                          ?.Include(p => p.DebtControlInfo)
                          ?.Include(p => p.DebtCalcMethodInfo)
                          ?.Include(p => p.FranchisingInfo)
                          ?.Include(p => p.ClientConnectionInfo);

            if (clients?.FirstOrDefault() != null)
            {
                var client = clients.FirstOrDefault();
                var model  = _clientDebtDetailsMapper.Map(client);

                model.Id = id;
                // Check all properties for null (i.e not mapped subject to Mapping Condition)
                model.DebtControl  = model.DebtControl ?? new DebtControlDto();
                model.BillSettings = model.BillSettings ?? new BillSettingsDto();

                model.ClientConnection = model.ClientConnection ?? new ClientConnectionDto();
                model.BillOptionsAll   = model.BillOptionsAll ?? new List <BillOptionsDto>();
                model.PrintJobsAll     = model.PrintJobsAll ?? new List <PrintJobDto>();

                // DebtCalc Method Types
                var debtCalcMethodsAll = _context.Set <DebtCalcMethodType>()
                                         .GetAll()
                                         ?.Select(d => new DebtCalcMethodTypeDto
                {
                    DebtCalcMethodTypeId = d.DebtCalcMethodTypeId,
                    Name = d.Name
                })
                                         ?.ToList();
                model.DebtCalcMethodsAll = debtCalcMethodsAll ?? new List <DebtCalcMethodTypeDto>();

                // Add items into PrintJobsAll if its Count < PrintJobsCapacity
                for (int i = 0; i < model.PrintJobsCapacity; i++)
                {
                    if (model.PrintJobsAll.ElementAtOrDefault(i) == null)
                    {
                        model.PrintJobsAll.Add(new PrintJobDto {
                            DocumentToPrintCopies = 0
                        });
                    }
                    else
                    {
                        model.PrintJobsAll[i].Active = true;
                    }
                }
                // Add items into BillOptionsAll if its Count < BillOptionsCapacity
                for (int i = 0; i < model.BillOptionsCapacity; i++)
                {
                    if (model.BillOptionsAll.ElementAtOrDefault(i) == null)
                    {
                        model.BillOptionsAll.Add(new BillOptionsDto {
                            Limit = 0
                        });
                    }
                    else
                    {
                        model.BillOptionsAll[i].Active = true;
                    }
                }

                // Franchising Types
                var franchisingTypesAll = _context.Set <FranchisingType>()
                                          .GetAll()
                                          ?.Select(d => new FranchisingTypeDto
                {
                    Name = d.Name,
                    FranchisingTypeId = d.FranchisingTypeId
                })
                                          ?.ToList();
                model.FranchisingTypesAll = franchisingTypesAll ?? new List <FranchisingTypeDto>();

                // Franchising Clients
                if (_context.Set <FranchisingInfo>().GetAll().Count() > 0)
                {
                    model.FranchisingClients = _context.Set <Point>()
                                               .GetAll()
                                               ?.Include(p => p.FranchisingInfo)
                                               ?.Select(d => new FranchisingClientDto
                    {
                        FranchisingClientDtoId = d.FranchisingInfo.PointNumber,
                        Name = d.NamePoint
                    })
                                               ?.ToList()
                                               ?? model.FranchisingClients;
                }
                // DocumentTemplates
                model.DocumentTemplatesAll = _context.Set <DocumentTemplate>()
                                             .GetAll()
                                             ?.Select(d => new DocumentTemplateDto
                {
                    DocumentTemplateId = d.DocumentTemplateId,
                    Name = d.Name
                })
                                             ?.ToList()
                                             ?? model.DocumentTemplatesAll;

                //// Check all other properties here.....
                return(PartialView(model));
            }
            else
            {
                _logger.LogWarning($"Customer with ID: {id} NOT FOUND!");
                return(NotFound($"Клиент с id: {id} не найден."));
            }
        }
        public IActionResult ClientContacts(int id)
        {
            _logger.LogInformation($"Getting Customer CONTACT INFO, ID: {id}, user: {User.Identity.Name}");
            try
            {
                _clientContactsMapper = _entityMapperContextBase.Set <Point, ClientContactsEditViewModel>(cfg =>
                {
                    cfg.CreateMap <Point, ClientContactsEditViewModel>()
                    .ForMember(dest => dest.LegalAddress, opt => opt.MapFrom(src => src.Address))
                    .ForMember(dest => dest.PhoneNumber1, opt => opt.MapFrom(src => src.Telefon))
                    .ForMember(dest => dest.ContactFullName1, opt => opt.MapFrom(src => src.ContactPerson))
                    .ForMember(dest => dest.Email1, opt => opt.MapFrom(src => src.Email))
                    .ForMember(dest => dest.FirstSignatory, opt => opt.MapFrom(src => src.Name1Person))
                    .ForMember(dest => dest.SecondSignatory, opt => opt.MapFrom(src => src.Name2Person))
                    .ForMember(dest => dest.ContactPhonesAll, opt => opt.MapFrom(src => src.ContactPhoneInfo))
                    .ForMember(dest => dest.ContactEmailsAll, opt => opt.MapFrom(src => src.ContactEmailInfo));
                }
                                                                                                          );
            }
            catch (Exception ex)
            {
                _logger.LogError($"Mapping error: {ex.Message}");
            }

            var model = _context.Set <Point>()
                        .FindBy(p => p.PointNumber == id)
                        ?.Include(p => p.ContactPhoneInfo)
                        ?.Include(p => p.ContactEmailInfo)
                        ?.Select(c => _clientContactsMapper.Map(c))
                        ?.FirstOrDefault();

            if (model != null)
            {
                model.Id = id;
                // Fill ContactPhonesView
                for (int i = 0; i < model.ContactPhonesCapacity; i++)
                {
                    if (model.ContactPhonesAll.ElementAtOrDefault(i) != null)
                    {
                        model.ContactPhonesView.Add(model.ContactPhonesAll.ElementAtOrDefault(i));
                    }
                    else
                    {
                        model.ContactPhonesView.Add(new ContactPhoneDto
                        {
                            PhoneNumber     = string.Empty,
                            ContactFullName = string.Empty
                        });
                    }
                }
                // Fill ContactEmailsView
                for (int i = 0; i < model.ContactEmailsCapacity; i++)
                {
                    if (model.ContactEmailsAll.ElementAtOrDefault(i) != null)
                    {
                        model.ContactEmailsView.Add(model.ContactEmailsAll.ElementAtOrDefault(i));
                    }
                    else
                    {
                        model.ContactEmailsView.Add(new ContactEmailDto
                        {
                            Email             = string.Empty,
                            IncludeToMailList = false
                        });
                    }
                }
                return(PartialView(model));
            }
            else
            {
                _logger.LogWarning($"Customer with ID: {id} NOT FOUND!");
                return(NotFound($"Клиент с id: {id} не найден."));
            }
        }
示例#7
0
        public IActionResult CreateTicket()
        {
            _clientMapper = _entityMapperContextBase.Set <Point, ClientDto>(cfg =>
            {
                cfg.CreateMap <Point, ClientDto>()
                .ForMember(dest => dest.ClientId, opt => opt.MapFrom(src => src.PointNumber))
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.NamePoint));
            });
            var clients = _context.Set <Point>()
                          ?.FindBy(p => p.CliGroupNumber == 7 || p.CliGroupNumber == 2)
                          ?.Include(c => c.CliGroup)
                          ?.OrderBy(c => c.NamePoint)
                          ?.Select(enity => _clientMapper.Map(enity));

            if (clients != null)
            {
                TicketCreateViewModel model = new TicketCreateViewModel();
                // Clients
                model.Clients = clients.ToList();
                // Communication types
                var communicationTypes = _context.Set <PointCommunicationType>()
                                         ?.GetAll()
                                         ?.Select(pct => new PointCommunicationTypeDto
                {
                    PointCommunicationTypeId = pct.PointCommunicationTypeId,
                    Name = pct.Name
                });
                model.PointCommunicationTypes = communicationTypes?.ToList() ?? model.PointCommunicationTypes;
                //додавання типу заявок (категорія)
                IQueryable <TicketSubjectDto> subjectsParents = _context.Set <TicketSubject>()
                                                                ?.GetAll()
                                                                ?.Where(t => t.ParentId == null)
                                                                ?.Select(t => new TicketSubjectDto
                {
                    Name            = t.TicketSubjectName,
                    TicketSubjectId = t.TicketSubjectId
                });
                //підкатегорія (тема)
                //IQueryable<TicketSubjectDto> subjectFirstChildren = _context.Set<TicketSubject>()
                //    ?.GetAll()
                //    ?.Where(t => t.ParentId != null)
                //    ?.Select(t => new TicketSubjectDto
                //    {
                //        Name = t.TicketSubjectName,
                //        TicketSubjectId = t.TicketSubjectId
                //    });

                //model.TicketSubjectFirstChildren = subjectFirstChildren?.ToList() ?? model.TicketSubjectFirstChildren;
                model.TicketSubjectParents = subjectsParents?.ToList() ?? model.TicketSubjectParents;


                //TMP!
                model.TicketSubjectLastChildren = _context.Set <TicketSubject>()
                                                  ?.GetAll()
                                                  ?.Where(i => i.ParentId == 16)
                                                  ?.Select(s => new TicketSubjectOptionDto
                {
                    Active          = false,
                    Name            = s.TicketSubjectName,
                    TicketSubjectId = s.TicketSubjectId
                }).ToList();
                //END TMP

                return(View(model));
            }
            return(NotFound("Ticket Subjects are not found!"));
        }