Example #1
0
        public async Task <IActionResult> Get(ActionQueryArgs <ClientModel> args)
        {
            try
            {
                if (!string.IsNullOrEmpty(args.CondictionString))
                {
                    args.Condiction = JETech.DevExtremeCore.Converter.FilterToExpresion <ClientModel>(args.CondictionString);
                }
                var resultCli = _clientService.GetClients(args);

                var result = new ActionPaginationResult <List <ClientModel> >
                {
                    Data       = await resultCli.Data.AsNoTracking().ToListAsync(),
                    GroupCount = resultCli.GroupCount,
                    TotalCount = resultCli.TotalCount
                };

                return(Ok(result));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(String.Empty, JETechException.Parse(ex).AppMessage);
                throw;
            }
        }
        public async Task <IActionResult> Create(AddUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var user = _userConverterHelper.ToUserModel(model);

                    var result = await _userManager.CreateAsync(user);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction(nameof(Login)));
                    }
                    ModelState.AddModelError("", "Ha ocurrido un error inesperado.");
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", JETechException.Parse(ex).AppMessage);
                }
            }
            return(View(model));
        }
        public async Task <IActionResult> Login(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var loginModel = _userConverterHelper.ToLoginModel(model);

                    var result = await _userManager.LoginAsync(loginModel);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    ModelState.AddModelError("", new JETechException("Invalid User.").AppMessage);
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", JETechException.Parse(ex).AppMessage);
                }
            }
            return(View());
        }