public async Task <BlTResult <View.Models.Scare> > CreateScareAsync(CreateScareRequest request, Monster monster) { Monsters.DAL.Models.Door door = await _repository.GetDoorAsync(request.DoorId).ConfigureAwait(false); if (door == null) { string errorMsg = $"Create scare failed. Door doesnt exist. Request: {request.ToString()} Monster: {monster.ToString()} "; _logger.LogError(errorMsg); return(new BlTResult <View.Models.Scare>() { IsSuccess = false, ErrorMsg = errorMsg, StatusCode = StatusCodes.Status400BadRequest }); } if (door.LastScare.Date >= DateTime.Today.Date) { string errorMsg = $"Create scare failed. Door already in use today by someone. Request: {request.ToString()} Monster: {monster.ToString()} "; _logger.LogError(errorMsg); return(new BlTResult <View.Models.Scare>() { IsSuccess = false, ErrorMsg = errorMsg, StatusCode = StatusCodes.Status409Conflict }); } try { door.LastScare = DateTime.Today; var updateResult = await _repository.UpdateDoorAsync(door).ConfigureAwait(false); Monsters.DAL.Models.Scare createResult = await _repository.CreateScareAsync( new Monsters.DAL.Models.Scare() { Id = Guid.NewGuid().ToString(), Door = door, MonsterId = monster.Id, ScareBegin = DateTime.Now }).ConfigureAwait(false); return(new BlTResult <View.Models.Scare>() { IsSuccess = true, Data = PrimitiveMapperHelper.Map(createResult) }); } catch (Exception ex) { string errorMsg = $"Create scare failed. Request: {request.ToString()}. Monster: {monster.ToString()}. Error: {ex.ToString()}"; _logger.LogError(errorMsg); return(new BlTResult <View.Models.Scare>() { IsSuccess = false, ErrorMsg = errorMsg, StatusCode = StatusCodes.Status400BadRequest }); } }
public async Task <BlTResult <View.Models.Scare> > EndScareAsync(EndScareRequest request) { try { Monsters.DAL.Models.Scare scare = await _repository.UpdateScareAsync(request.ScareId, DateTime.Now); return(new BlTResult <View.Models.Scare>() { IsSuccess = true, Data = PrimitiveMapperHelper.Map(scare) }); } catch (Exception ex) { string errorMsg = $"Error ending scare. Request: {request.ToString()} Error: {ex.ToString()}"; _logger.LogError(errorMsg); return(new BlTResult <View.Models.Scare>() { IsSuccess = false, ErrorMsg = $"errorMsg" }); } }