public void FillAdmTempDataWhenCantSaveAdm(string name, string mobileNumber, string email, int sex)
 {
     var adm = new Adm {Person = BuildPersonWith(name, mobileNumber, email, sex)};
     
     _admController.Manage(adm);
     Assert.That(_admController.TempData[nameof(Adm)] as Adm, Is.EqualTo(adm));
 }
        public JsonResult ListarPaginado(string Nome)
        {
            var paginaAtual = int.Parse(Request.Params[Constants.START_PAGE]);

            var adm = new Adm {Person = new Person {Name = Nome}};

            var retorno = _admBusiness.SelectWithPagination(adm, paginaAtual);

            var totalRegistros = _admBusiness.Total(adm);

            return BuildJsonObject(retorno, totalRegistros);
        }
        public JsonResult Salvar(Adm adm)
        {
            var mensagem = GetSuccessMensagemForSaveOrUpdate(adm.Id);

            try
            {
                ValidateAndSave(adm);
            }
            catch (Exception ex)
            {
                mensagem = GetErrorMessageFromExceptionType(ex);
            }

            return Json(new {mensagem, administradorId = adm.Id});
        }
        public ActionResult Manage(Adm adm)
        {
            var actionName = nameof(Index);

            try
            {
                _admBusiness.SaveAndReturn(adm);
            }
            catch (Exception ex)
            {
                TempData[nameof(Adm)] = adm;
                TempData[Constants.ERROR] = ex.Message;
                actionName = nameof(Manage);
            }

            return RedirectToAction(actionName, "Adm");
        }
 public static Func<Adm, bool> AdmFilterCondition(Adm adm)
 {
     return a => string.IsNullOrEmpty(adm.Person.Name) ||
                 a.Person.Name.ToLower().Contains(adm.Person.Name.ToLower());
 }
        private void BuildDropDownLists(Adm model)
        {
            ViewBag.EstadoCivil = BuildListItemfromEnum<MaritalStatusEnum>(model.Person.MaritalState.ToString());
            ViewBag.Sexo = BuildListItemfromEnum<SexEnum>(model.Person.Sex.ToString());

            ViewBag.Cidades = model.Id > 0
                ? BuildListSelectListItemWith(
                    _cityBusiness.SelectWithFilter(a => a.State.Code.Equals(model.Person.Address.State)), "Name", "Id",
                    model.Person.Address.CityId.ToString())
                : BuildListSelectListItemWith(new List<City>(), "Name", "Id");

            ViewBag.Estados = BuildListSelectListItemWith(_stateBusiness.GetAll().ToList(), "Name", "Code");
        }
 private void ValidateAndSave(Adm adm)
 {
     _personBusiness.ValidadePerson(adm.Person);
     _admBusiness.SaveAndReturn(adm);
 }