public ActionResult List(PersonsListModel model)
        {
            var persons = MdlBlockDofSPersonsRepository
                          .GetMany(p => (model.FirstName != null && p.firstname.ToLower().Contains(model.FirstName.ToLower())) ||
                                   (model.MiddleName != null && p.middlename.ToLower().Contains(model.MiddleName.ToLower())) ||
                                   (model.LastName != null && p.lastname.ToLower().Contains(model.LastName.ToLower())))
                          .ToArray();

            return(Json(new { Persons = persons }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            var persons = await _persons.GetList();

            var result = new PersonsListModel {
                Persons = persons
                          .Select(CreateModel)
                          .ToArray()
            };

            return(View(result));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> AddPerson(PersonModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (!Name.IsValid(model.FirstName))
            {
                ModelState.AddModelError(nameof(model.FirstName), "FirstName is invalid");
            }
            if (!Name.IsValid(model.LastName))
            {
                ModelState.AddModelError(nameof(model.LastName), "LastName is invalid");
            }
            if (!Age.IsValid(model.Age))
            {
                ModelState.AddModelError(nameof(model.Age), "Age is invalid");
            }
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var firstName = new Name(model.FirstName);
            var lastName  = new Name(model.LastName);
            var person    = new Person(
                new PersonalName(firstName, lastName),
                new Age(model.Age));

            await _persons.Add(person);

            await _unitOfWork.Commit();

            var persons = await _persons.GetList();

            var result = new PersonsListModel {
                Persons = persons
                          .Select(CreateModel)
                          .ToArray()
            };

            return(View("Index", result));
        }