public async Task <ActionResult> RegisterUser(User user) { if (!ModelState.IsValid) { return(GetValidationMessages().ToJsonResult()); } var existsUserName = await ModelRepository .SingleAsync(existingUser => string.Equals(existingUser.UserName, user.UserName, StringComparison.InvariantCultureIgnoreCase)).ConfigureAwait(false); if (existsUserName != null) { return(string.Format("El usuario '{0}' ya existe en el sistema", user.UserName).ToJsonResult()); } user.RoleId = Settings.DefaultUserRoleDbId; user.IsAuthorized = false; var userToSave = Mapper.Map <DataAccess.Entities.User>(user); userToSave = await ModelRepository.AddAsync(userToSave).ConfigureAwait(false); var savedUser = Mapper.Map <User>(userToSave); var recipients = (await ModelRepository .GetAllAsync(admin => admin.RoleId == Settings.AdministratorUserRoleDbId)) .Select(admin => admin.Email); var htmlBody = user.GetHtmlFromXslt(Server.MapPath(Settings.NewUserTemplateFilePath), XsltParameters); await _emailSender.Send(Settings.SmtpEmail, recipients, Settings.NewUserAuthorizationSubject, htmlBody); return(savedUser.ToJsonResult()); }
public override async Task <ActionResult> Get() { var dbUsers = await ModelRepository.GetAllAsync(); var users = Mapper.Map <IEnumerable <User> >(dbUsers); var jsonResult = new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase) { { "users", users }, { "isLoggedInUserAdmin", LoggedInUserInfo.User.IsAdministrator() } }; return(jsonResult.ToJsonResult()); }
public virtual async Task <ActionResult> Search(int initialFolio, int finalFolio) { var dbReports = await ModelRepository .GetAllAsync(report => report.Id >= initialFolio && report.Id <= finalFolio); var reports = Mapper.Map <IEnumerable <Report> >(dbReports); var jsonResult = new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase) { { ModelDescription, reports } }; return(jsonResult.ToJsonResult()); }