public ChartController(ITimerAccess timerAccess, ITimeBuilder timeBuilder, ITimeGetter timeGetter, IRequestReader requestReader, ITimerCalculator timerCalculator) { _timerAccess = timerAccess; _timeBuilder = timeBuilder; _timeGetter = timeGetter; _requestReader = requestReader; _timerCalculator = timerCalculator; _timeZoneInfo = _timeBuilder.GetTimeZoneInfo(_requestReader.Read(TypeScript.HttpHeaders.Request.CurrentTimeZone)); }
public TimerController(ITimerAccess timerAccess, IRequestReader requestReader, ITimeBuilder timeBuilder, ITimerCalculator timerCalculator, IOvertimeAccess overtimeAccess) { _timerAccess = timerAccess; _requestReader = requestReader; _timeBuilder = timeBuilder; _timerCalculator = timerCalculator; _overtimeAccess = overtimeAccess; _timeZoneInfo = _timeBuilder.GetTimeZoneInfo(_requestReader.Read(HttpHeaders.Request.CurrentTimeZone)); }
public IHttpActionResult Logout() { var result = new LogoutViewModel(); Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie); result.Result = true; if (result.Result) { var notificationHub = GetHub <NotificationHub, INotificationHub>(); var connectionId = _requestReader.Read(TypeScript.HttpHeaders.Request.SignalRConnectionId); if (!string.IsNullOrEmpty(connectionId)) { notificationHub.Clients.AllExcept(connectionId).UpdateModel(new NotificationModel() { Username = UserName, Action = string.Format("È Offline!") }); } } return(Ok(result)); }
public async Task <IHttpActionResult> SaveUser(SaveUserBindingModel model) { var result = new SaveUserViewModel(); IdentityResult identityResult = null; ApplicationUser user = null; if (string.IsNullOrEmpty(model.Data.Id)) { user = new ApplicationUser() { UserName = model.Data.UserName, Email = model.Data.Email }; identityResult = await UserManager.CreateAsync(user, model.Data.Password); } else { user = await UserManager.FindByIdAsync(model.Data.Id); user.UserName = model.Data.UserName; user.Email = model.Data.Email; identityResult = await UserManager.UpdateAsync(user); } if (!identityResult.Succeeded) { result.Result = false; if (identityResult.Errors != null) { var firstError = identityResult.Errors.First(); result.Message = firstError; } } else { foreach (var roleId in user.Roles.Where(x => !model.Data.Roles.Contains(x.RoleId)).ToList()) { var role = await RoleManager.FindByIdAsync(roleId.RoleId); if (await UserManager.IsInRoleAsync(user.Id, role.Name)) { var rolesResult = await UserManager.RemoveFromRoleAsync(user.Id, role.Name); if (!rolesResult.Succeeded) { result.Result = false; if (rolesResult.Errors != null) { var firstError = rolesResult.Errors.First(); result.Message = firstError; } break; } } } foreach (var role in model.Data.Roles) { if (!await UserManager.IsInRoleAsync(user.Id, role)) { var rolesResult = await UserManager.AddToRoleAsync(user.Id, role); if (!rolesResult.Succeeded) { result.Result = false; if (rolesResult.Errors != null) { var firstError = rolesResult.Errors.First(); result.Message = firstError; } break; } } } result.Result = true; } if (result.Result) { var notificationHub = GetHub <NotificationHub, INotificationHub>(); var connectionId = _requestReader.Read(HttpHeaders.Request.SignalRConnectionId); if (!string.IsNullOrEmpty(connectionId)) { notificationHub.Clients.AllExcept(connectionId).UpdateModel(new NotificationModel() { Username = UserName, Action = string.Format("Ha salvato l'user {0}", model.Data.UserName) }); } } return(Ok(result)); }
public static Task <object> Read(this IRequestReader reader, RequestBinderContext context) { return(reader.Read(new RequestReaderContext(context.Configuration, context.RequestContext))); }