public IActionResult GetDetail(int id, [FromQuery] BookingQueryProjection projection, [FromQuery] BookingQueryOptions options) { var getManagerType = projection.GetFieldsArr().Contains(BookingQueryProjection.MANAGER_TYPE); projection = new BookingQueryProjection { fields = BookingQueryProjection.DETAIL }; var entity = _service.GetBookingDetail(id, projection); if (entity == null) { return(NotFound(AppResult.NotFound())); } var validationData = _service.ValidateGetBookingDetail(entity, User, options); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var obj = _service.GetBookingDynamic(entity, projection, options); if (getManagerType) { obj["manager_type"] = validationData.TempData["manager_type"]; } return(Ok(AppResult.Success(data: obj))); }
public IActionResult GetSecret() { var clientId = HttpContext.Items[Constants.RequestItemKey.CLIENT_ID] as string; var secret = _service.AppClients.Id(clientId).First().SecretKey; return(Ok(AppResult.Success(secret))); }
public async Task <IActionResult> UpdateImage(int id, [FromForm] UpdateProductModelImageModel model) { var entity = _service.ProductModels.Id(id).FirstOrDefault(); if (entity == null) { return(NotFound(AppResult.NotFound())); } var validationData = _service.ValidateUpdateProductModelImage(User, entity, model); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var(relPath, fullPath) = _service.GetProductModelImagePath(entity, Settings.Instance.UploadFolderPath, Settings.Instance.WebRootPath); var oldRelPath = entity.Image; _service.UpdateProductModelImage(entity, relPath); context.SaveChanges(); // must be in transaction var ev = _ev_service.UpdateProductModelImage(entity, User); context.SaveChanges(); await _service.SaveReplaceProductModelImage(model, fullPath, Settings.Instance.WebRootPath, oldRelPath); return(Created($"/{relPath}", AppResult.Success(relPath))); }
public async Task <IActionResult> RemoveRole(string name) { var entity = _service.GetRoleByName(name); if (entity == null) { return(NotFound(AppResult.NotFound())); } var validationData = _service.ValidateDeleteRole(User, entity); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var result = await _service.RemoveRoleAsync(entity); if (result.Succeeded) { return(Ok(AppResult.Success(result))); } foreach (var err in result.Errors) { ModelState.AddModelError(err.Code, err.Description); } return(BadRequest(AppResult.FailValidation(ModelState))); }
public async Task <IActionResult> Create(CreateAppUserModel model) { if (ModelState.IsValid) { var validationData = _service.ValidateCreateAppUser(User, model); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } IdentityResult result; using (var trans = context.Database.BeginTransaction()) { var entity = _service.ConvertToUser(model); result = await _service .CreateUserWithRolesTransactionAsync(entity, model.Password, new[] { model.Role }); if (result.Succeeded) { trans.Commit(); _logger.CustomProperties(entity).Info("Register new user"); return(Created($"/{Business.Constants.ApiEndpoint.USER_API}?id={entity.Id}", AppResult.Success(entity.Id))); } } foreach (var err in result.Errors) { ModelState.AddModelError(err.Code, err.Description); } } var appResult = ResultHelper.MakeInvalidAccountRegistrationResults(ModelState); return(BadRequest(appResult)); }
public async Task <IActionResult> SyncRoomWithFAP() { var validationData = _service.ValidateSyncRoomWithFap(User); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } int updated; using (var trans = context.Database.BeginTransaction()) { var fapClient = HttpContext.RequestServices.GetRequiredService <FptFapClient>(); updated = await _service.SyncRoomWithFapAsync(fapClient); //log event var ev = _sysService.GetEventForSyncRoomWithFap( $"Admin {UserEmail} synced rooms information with FAP", User); _sysService.CreateAppEvent(ev); //end log event context.SaveChanges(); trans.Commit(); } return(Ok(AppResult.Success(data: updated))); }
public IActionResult GetConfig() { var config = Business.Settings.Instance; return(Ok(AppResult.Success(data: new { student_allowed = config.StudentAllowed }))); }
public IActionResult GetTestClientInfo(string clientId) { var client = _service.AppClients.Id(clientId).First(); var now = DateTime.UtcNow; var df = "ddMMyyyyHHmmss"; var dtStr = now.ToString(df); var hashed = _identityService.ComputeHash(dtStr, df, client.SecretKey); return(Ok(AppResult.Success($"AppClient {clientId}!{dtStr}!{df}!{hashed}"))); }
protected async Task <AppResult <List <GameCard> > > GetTargetsByCharacterName(DtoEffectTargets effect, TargetingEffectParameters parameters, Game game) { var name = parameters.TargetParameter.ToString(); var targets = await dbContext.GameCards.IncludeAll() .Where(_ => _.Card.Character.Name == name && _.CardLocation == CardLocation.Board) .ToListAsync(); return(AppResult <List <GameCard> > .Success(targets)); }
public async Task <AppResult <User> > CreateUser(string mail, CancellationToken cancellationToken = default(CancellationToken)) { var user = new User { Mail = mail }; await this.dbContext.AddAsync(user, cancellationToken); return(AppResult <User> .Success(user)); }
private async Task <AppResult <Move> > GetLastEndTurn(Guid gameId) { var lastEndTurn = await this.dbContext.Moves .Include(_ => _.Game) .Include(_ => _.SourceEntity) .ThenInclude(_ => _.User) .Where(_ => _.Type == MoveType.EndTurn && _.Game.Id == gameId) .OrderByDescending(_ => _.Date) .FirstOrDefaultAsync(); return(AppResult <Move> .Success(lastEndTurn)); }
public IActionResult GetRoles() { var validationData = _service.ValidateGetRoles(User); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var result = _service.Roles.ToList(); return(Ok(AppResult.Success(result))); }
public async Task <IActionResult> SendUnsentEvents() { var validationData = _service.ValidateSendEvents(User); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var dt = await Startup.Scheduler.TriggerSendUnsentEventsJob(null); return(Ok(AppResult.Success(dt))); }
public async Task <IActionResult> PushNoti(PushNotiModel model) { var user = _identityService.Users.ByEmail(model.Email).FirstOrDefault(); if (user == null) { return(NotFound(AppResult.NotFound())); } var result = await _adminService.PushNotiToUser(user, model); return(Ok(AppResult.Success(result))); }
public IActionResult Create(CreateResourceModel model) { var validationData = _service.ValidateCreateResource(User, model); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var entity = _service.CreateResource(model); context.SaveChanges(); return(Created($"/{Business.Constants.ApiEndpoint.RESOURCE_API}?id={entity.Id}", AppResult.Success(entity.Id))); }
public async Task <IActionResult> GetProfile() { var validationData = _service.ValidateGetProfile(User); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var entity = await _service.GetUserByIdAsync(UserId); var data = _service.GetUserProfile(entity); return(Ok(AppResult.Success(data))); }
public async Task <IActionResult> ClearAllEvents() { var validationData = _service.ValidateClearAllEvents(User); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var task = _service.ClearAllQCEvents(); _service.ClearAllQCEventImages(Settings.Instance.QCEventImageFolderPath); var deleted = await task; return(Ok(AppResult.Success(deleted))); }
private async Task <AppResult <List <DtoCard> > > GetDtoCardsFromGameCards(List <GameCard> gameCards, Guid gameId) { var dtoCards = new List <DtoCard>(); var lastEndTurnResult = await this.GetLastEndTurn(gameId); if (lastEndTurnResult.IsErrorResult) { return(lastEndTurnResult.GetErrorAppResult <List <DtoCard> >()); } var lastEndTurn = lastEndTurnResult.SuccessReturnValue; foreach (var gameCard in gameCards) { var effects = new List <DtoEffect>(); foreach (var cardEffect in gameCard.Card.Effects) { var effectResult = await this.effectsService.GetDtoEffect(cardEffect); if (effectResult.IsErrorResult) { return(effectResult.GetErrorAppResult <List <DtoCard> >()); } effects.Add(effectResult.SuccessReturnValue); } var lastAttack = await dbContext.Moves .Include(_ => _.SourceEntity) .Where(_ => _.SourceEntity.Id == gameCard.Id) .OrderByDescending(_ => _.Date) .FirstOrDefaultAsync(); dtoCards.Add(new DtoCard { Id = gameCard.Id, Name = gameCard.Card.Character.Name, Title = gameCard.Card.Title.Name, Cost = gameCard.Card.Cost, Attack = gameCard.Card.Attack, CanAttack = lastAttack == null || lastEndTurn == null || lastAttack.Date < lastEndTurn.Date, Health = gameCard.Health, StatsModifiersCount = gameCard.StatModifiersCount, Effects = effects }); } return(AppResult <List <DtoCard> > .Success(dtoCards)); }
public IActionResult UpdateSeenStatus([FromQuery][QueryObject] QCEventQueryFilter filter, [FromQuery] QCEventQuerySort sort, [FromQuery] QCEventQueryPaging paging, [FromQuery] QCEventQueryOptions options) { var validationData = _service.ValidateUpdateSeenStatus( User, filter, sort, paging, options); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var query = _service.GetQueryableQCEventForUpdate(options, filter, sort, paging); var updated = _service.UpdateEventsSeenStatus(query, true); return(Ok(AppResult.Success(updated))); }
public IActionResult Count([FromQuery][QueryObject] QCEventQueryFilter filter, [FromQuery] QCEventQuerySort sort, [FromQuery] QCEventQueryPaging paging, [FromQuery] QCEventQueryOptions options) { var validationData = _service.ValidateCountQCEvents( User, filter, sort, paging, options); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var query = _service.GetQueryableQCEvent(options, filter, sort, paging); var count = query.Count(); return(Ok(AppResult.Success(count))); }
public async Task <AppResult <DtoEffect> > GetDtoEffect(CardEffect cardEffect) { var dtoEffect = new DtoEffect { Id = cardEffect.Id, EffectType = cardEffect.EffectType }; var configureResult = await this.effects[cardEffect.EffectType].ConfigureDtoEffect(cardEffect, dtoEffect); if (configureResult.IsErrorResult) { return(configureResult.GetErrorAppResult <DtoEffect>()); } return(AppResult <DtoEffect> .Success(dtoEffect)); }
public IActionResult Create(CreateProductionBatchModel model) { var validationData = _service.ValidateCreateProductionBatch(User, model); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var entity = _service.CreateProductionBatch(model); context.SaveChanges(); // must be in transaction var ev = _ev_service.CreateProductionBatch(entity, User); context.SaveChanges(); return(Created($"/{Business.Constants.ApiEndpoint.PRODUCTION_LINE_API}?id={entity.Id}", AppResult.Success(entity.Id))); }
public async Task <IActionResult> GetCalendar( [FromQuery][DefaultDateTimeModelBinder] DateTime date, [FromQuery] BookingQueryProjection projection, [FromQuery] BookingQueryOptions options) { var validationData = _service.ValidateGetOwnerBookings( User, date, projection, options); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var member = _memberService.Members.Id(UserId).FirstOrDefault(); var result = await _service.QueryCalendarDynamic(User, member, projection, date, validationData.TempData, options); return(Ok(AppResult.Success(data: result))); }
protected async Task <AppResult <List <GameCard> > > GetTargetsByIds(DtoEffectTargets effect, TargetingEffectParameters parameters, Game game) { var targetsCount = Convert.ToInt32(parameters.TargetParameter); if (targetsCount != effect.TargetIds.Count) { return(AppResult <List <GameCard> > .Error(AppActionResultType.RuleError, $"You must choose exactly {targetsCount} targets to destroy.")); } var targets = await dbContext.GameCards.IncludeAll() .Where(_ => effect.TargetIds.Contains(_.Id)) .ToListAsync(); if (targets.Count != effect.TargetIds.Count) { return(VoidAppResult.Error(ErrorPreset.InvalidTargets).GetErrorAppResult <List <GameCard> >()); } return(AppResult <List <GameCard> > .Success(targets)); }
public async Task <IActionResult> CreateRole(CreateRoleModel model) { var validationData = _service.ValidateCreateRole(User, model); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var result = await _service.CreateRoleAsync(model); if (result.Succeeded) { return(Ok(AppResult.Success(result))); } foreach (var err in result.Errors) { ModelState.AddModelError(err.Code, err.Description); } return(BadRequest(AppResult.FailValidation(ModelState))); }
public async Task <AppResult <GameCard> > GenerateStormling(User user) { var stormlingCard = await this.dbContext.Cards.SingleOrDefaultAsync(_ => _.Id == StormlingId); if (stormlingCard == null) { return(VoidAppResult.Error(ErrorPreset.OnLoadingData).GetErrorAppResult <GameCard>()); } var stormling = new GameCard { Id = Guid.NewGuid(), Health = stormlingCard.BaseHealth, Card = stormlingCard, CardLocation = CardLocation.Board, User = user }; return(AppResult <GameCard> .Success(stormling)); }
public async Task <IActionResult> Get([FromQuery][QueryObject] QCEventQueryFilter filter, [FromQuery] QCEventQuerySort sort, [FromQuery] QCEventQueryProjection projection, [FromQuery] QCEventQueryPaging paging, [FromQuery] QCEventQueryOptions options) { var validationData = _service.ValidateGetQCEvents( User, filter, sort, projection, paging, options); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var result = await _service.QueryQCEventDynamic( projection, options, Settings.Instance.QCEventImageFolderPath, filter, sort, paging); if (options.single_only && result == null) { return(NotFound(AppResult.NotFound())); } return(Ok(AppResult.Success(result))); }
public IActionResult GetDetail(string code, [FromQuery] RoomQueryProjection projection, [FromQuery] RoomQueryOptions options, bool hanging = false) { var checkerValid = projection.GetFieldsArr().Contains(RoomQueryProjection.CHECKER_VALID); projection = new RoomQueryProjection { fields = RoomQueryProjection.DETAIL }; var entity = _service.Rooms.Code(code).FirstOrDefault(); if (entity == null) { return(NotFound(AppResult.NotFound())); } var validationData = _service.ValidateGetRoomDetail(entity, hanging, options); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } if (hanging) { _service.ReleaseHangingRoomByHangingUserId(UserId); _service.ChangeRoomHangingStatus(entity, true, UserId); context.SaveChanges(); } var obj = _service.GetRoomDynamic(entity, projection, options); if (checkerValid) { var isRoomChecker = User.IsInRole(RoleName.ROOM_CHECKER); var valid = _memberService.AreaMembers.OfArea(entity.BuildingAreaCode).Select(o => o.MemberId) .Contains(UserId) && isRoomChecker; obj["checker_valid"] = valid; } return(Ok(AppResult.Success(data: obj))); }
public async Task <IActionResult> Get([FromQuery][QueryObject] DepartmentQueryFilter filter, [FromQuery] DepartmentQuerySort sort, [FromQuery] Business.Models.DepartmentQueryProjection projection, [FromQuery] DepartmentQueryPaging paging, [FromQuery] DepartmentQueryOptions options) { var validationData = _service.ValidateGetDepartments( filter, sort, projection, paging, options); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var result = await _service.QueryDepartmentDynamic( projection, validationData.TempData, filter, sort, paging, options); if (options.single_only && result == null) { return(NotFound(AppResult.NotFound())); } return(Ok(AppResult.Success(data: result))); }
public async Task <IActionResult> Get([FromQuery][QueryObject] ProductionBatchQueryFilter filter, [FromQuery] ProductionBatchQuerySort sort, [FromQuery] ProductionBatchQueryProjection projection, [FromQuery] ProductionBatchQueryPaging paging, [FromQuery] ProductionBatchQueryOptions options) { var validationData = _service.ValidateGetProductionBatchs( User, filter, sort, projection, paging, options); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } var result = await _service.QueryProductionBatchDynamic( projection, options, filter, sort, paging); if (options.single_only && result == null) { return(NotFound(AppResult.NotFound())); } return(Ok(AppResult.Success(result))); }