Exemplo n.º 1
0
        private ClientIndexViewModel ToClientIndexViewModel(ApiClient client)
        {
            var apiClientId = client.ApiClientId;

            var application = client.Application ?? new Application
            {
                ApplicationName = "<Empty>"
            };

            var applicationName = application.ApplicationName;
            var name            = client.Name;
            var key             = client.Key;
            var secret          = client.Secret;
            var status          = client.Status;
            var sandboxTypeName = client.SandboxTypeName;

            ClientIndexViewModel viewModel = new ClientIndexViewModel
            {
                Id     = apiClientId, ApplicationName = applicationName, Name = name, Key = key, Secret = secret,
                Status = status, SandboxTypeName = sandboxTypeName,
                OperationalContextUri = application.OperationalContextUri
            };

            return(viewModel);
        }
        public IActionResult Index(string SearchTerm = null)
        {
            var model = new ClientIndexViewModel();

            model.Clients = clientService.GetClients(SearchTerm);
            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult Index()
        {
            ClientIndexViewModel model = new ClientIndexViewModel();

            model.Clients = ClientManager.GetAll();
            return(View(model));
        }
Exemplo n.º 4
0
        public ClientIndexViewModel PutClient(ClientIndexViewModel client)
        {
            var test = UserProfile.ApiClients.FirstOrDefault(c => c.Key == client.Key && c.ApiClientId == client.Id);

            if (test == null)
            {
                throw new KeyNotFoundException();
            }

            test.GenerateSecret();
            _repository.UpdateClient(test);
            AddClientStatusInfo(test);
            return(ToClientIndexViewModel(test));
        }
Exemplo n.º 5
0
        public IActionResult AddClient(ClientIndexViewModel model)
        {
            var names = db.Clients.Select(item => item.Name);

            ViewData["Message"] = "";
            model.Clients       = db.Clients.ToList();
            model.Ids           = db.Employees.Select(item => item.Id).ToList();
            if (model.Name == null || model.RepresentativeFIO == null || model.Address == null)
            {
                ViewData["Message"] += "Отсутствие значений в строках";
                return(View("~/Views/Client/Index.cshtml", model));
            }
            if (names.Contains(model.Name) || model.Name.Length == 0 || model.Name.Length > 25)
            {
                ViewData["Message"] += "Неправильный ввод названия";
                return(View("~/Views/Client/Index.cshtml", model));
            }
            else if (model.RepresentativeFIO.Length == 0 || model.RepresentativeFIO.Length > 100)
            {
                ViewData["Message"] += "Неправильный ввод ФИО представителя";
                return(View("~/Views/Client/Index.cshtml", model));
            }
            else if (model.Number.ToString().Length < 9 || model.Number.ToString().Length > 13)
            {
                ViewData["Message"] += "Неправильный ввод номера";
                return(View("~/Views/Client/Index.cshtml", model));
            }
            else if (model.Address.Length == 0 || model.Address.Length > 40)
            {
                ViewData["Message"] += "Неправильный ввод адреса";
                return(View("~/Views/Client/Index.cshtml", model));
            }
            else
            {
                var id = 0;
                if (db.Clients.Count() != 0)
                {
                    id = db.Clients.Select(item => item.Id).Max();
                }
                id++;
                db.Clients.Add(new Client()
                {
                    Id = id, Name = model.Name, Address = model.Address, Number = model.Number, RepresentativeFIO = model.RepresentativeFIO
                });
                db.SaveChanges();
                cache.Remove("Clients");
                cache.Set("Clients", db.Clients.ToList(), new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(10)));
                return(RedirectToAction("Index", "Client"));
            }
        }
Exemplo n.º 6
0
        public IActionResult UpdateClient(ClientIndexViewModel model, string action = null)
        {
            if (action != null)
            {
                return(DeleteClient(model.Id));
            }
            var names = db.Clients.Select(item => item.Name);

            ViewData["Message"] = "";
            model.Clients       = db.Clients.ToList();
            model.Ids           = db.Clients.Select(item => item.Id).ToList();
            if (model.Name == null || model.RepresentativeFIO == null || model.Address == null)
            {
                ViewData["Message"] += "Отсутствие значений в строках";
                return(View("~/Views/Client/Index.cshtml", model));
            }
            if (names.Contains(model.Name) || model.Name.Length == 0 || model.Name.Length > 25)
            {
                ViewData["Message"] += "Неправильный ввод названия";
                return(View("~/Views/Client/Index.cshtml", model));
            }
            else if (model.RepresentativeFIO.Length == 0 || model.RepresentativeFIO.Length > 100)
            {
                ViewData["Message"] += "Неправильный ввод ФИО представителя";
                return(View("~/Views/Client/Index.cshtml", model));
            }
            else if (model.Number.ToString().Length < 9 || model.Number.ToString().Length > 13)
            {
                ViewData["Message"] += "Неправильный ввод номера";
                return(View("~/Views/Client/Index.cshtml", model));
            }
            else if (model.Address.Length == 0 || model.Address.Length > 40)
            {
                ViewData["Message"] += "Неправильный ввод адреса";
                return(View("~/Views/Client/Index.cshtml", model));
            }
            else
            {
                var client = db.Clients.Where(item => item.Id == model.Id).FirstOrDefault();
                client.Name = model.Name;
                client.RepresentativeFIO = model.RepresentativeFIO;
                client.Number            = model.Number;
                client.Address           = model.Address;
                db.SaveChanges();
                cache.Remove("Clients");
                cache.Set("Clients", db.Clients.ToList(), new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(10)));
                return(RedirectToAction("Index", "Client"));
            }
        }
        public async Task <IActionResult> PutClient(ClientIndexViewModel clientViewModel)
        {
            var client = _repository.GetClient(clientViewModel.Key);

            if (client == null)
            {
                throw new KeyNotFoundException();
            }

            client.GenerateSecret();
            _repository.UpdateClient(client);
            await AddClientStatusInfo(client);

            return(Ok(ToClientIndexViewModel(client)));
        }
Exemplo n.º 8
0
        public IActionResult Index(int page = 1, string filterRepresFIO = "Все", string address = null, string type = null)
        {
            int           pageSize = 20;
            List <Client> clients;

            if (!cache.TryGetValue("Clients", out clients))
            {
                clients = db.Clients.ToList();
                cache.Set("Clients", db.Clients.ToList(), new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(10)));
            }
            List <int> Ids     = clients.Select(item => item.Id).ToList();
            var        repFios = clients.Select(item => item.RepresentativeFIO).ToList();

            repFios.Add("Все");

            if (filterRepresFIO != "Все")
            {
                clients = clients.Where(item => item.RepresentativeFIO == filterRepresFIO).ToList();
            }

            if (address != null)
            {
                clients = clients.Where(item => item.Address.Contains(address)).ToList();
            }

            if (type != null)
            {
                clients = type switch
                {
                    "Id" => clients.OrderBy(item => item.Id).ToList(),
                    "name" => clients.OrderBy(item => item.Name).ToList(),
                    "fio" => clients.OrderBy(item => item.RepresentativeFIO).ToList(),
                    "numb" => clients.OrderBy(item => item.Number).ToList(),
                    _ => clients.OrderBy(item => item.Address).ToList(),
                };
            }

            ClientIndexViewModel clientIndexViewModel = new ClientIndexViewModel()
            {
                Clients          = clients.Skip((page - 1) * pageSize).Take(pageSize).ToList(),
                Ids              = Ids,
                PageViewModel    = new PageViewModel(clients.Count, page, pageSize),
                FilterRepresFIOs = repFios
            };

            return(View(clientIndexViewModel));
        }
Exemplo n.º 9
0
        public ActionResult Index(SearchRequest searchRequest) // Create client 'No Match'
        {
            IList <Client> searchMatches = _clientServices.HandlesSearchRequest(searchRequest);

            var viewModel = new ClientIndexViewModel
            {
                Clients    = searchMatches,
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = 1,
                    ItemsPerPage = _pageSize,
                    TotalItems   = searchMatches.Count
                }
            };

            return(View(viewModel));
        }
Exemplo n.º 10
0
        public ActionResult Index(int page = 1)
        {
            IList <Client> allClients = _clientServices.GetAllClients();

            var list = allClients
                       .OrderBy(item => item.ClientID)
                       .Skip((page - 1) * _pageSize)
                       .Take(_pageSize);

            var viewModel = new ClientIndexViewModel
            {
                Clients    = list,
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = _pageSize,
                    TotalItems   = allClients.Count
                }
            };

            return(View(viewModel));
        }
Exemplo n.º 11
0
        // GET: Client
        public async Task <IActionResult> Index(ClientIndexViewModel model)
        {
            model.Pager ??= new PagerViewModel();
            model.Pager.CurrentPage = model.Pager.CurrentPage <= 0 ? 1 : model.Pager.CurrentPage;

            List <ClientViewModel> items = await _context.Clients.Skip((model.Pager.CurrentPage - 1) *PageSize).Take(PageSize).Select(c => new ClientViewModel()
            {
                Id          = c.Id,
                Name        = c.Name,
                Surname     = c.Surname,
                Email       = c.Email,
                PhoneNumber = c.PhoneNumber,
                IsAdult     = c.IsAdult
            }).ToListAsync();

            model.Items            = items;
            model.Pager.PagesCount = (int)Math.Ceiling(await _context.Clients.CountAsync() / (double)PageSize);



            return(View(model));
        }