private async Task GetModels(ConcurrentDictionary <string, object> lookupData) { var modelsResult = await modelService.GetAll(); if (modelsResult.ResultCode == ResultCode.Success) { var data = modelsResult.Data .Select(model => dataStructureConverter.Map <ModelModel, Model>(model)) .OrderBy(x => x.Id) .ToList(); lookupData.AddOrUpdate("models", data, (key, oldValue) => data); } }
public async Task <IActionResult> Post([FromBody] LocationModel locationModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var location = dataStructureConverter.Map <Location, LocationModel>(locationModel); var result = await locationService.Insert(location); if (result.ResultCode == ResultCode.Success) { return(CreatedAtRoute("GetLocation", new { id = result.Data }, result.Data)); } return(errorCodeConverter.Convert(result.ResultCode)); }
public async Task <IActionResult> Post([FromBody] VehicleModel vehicleModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var vehicle = dataStructureConverter.Map <Vehicle, VehicleModel>(vehicleModel); var result = await vehicleService.Insert(vehicle); if (result.ResultCode == ResultCode.Success) { return(CreatedAtRoute("GetVehicle", new { id = result.Data }, result.Data)); } return(errorCodeConverter.Convert(result.ResultCode)); }
public async Task <Result <UserModel> > Execute(LoginModel loginModel) { var userResult = await userService.GetUserByUsernameAndPassword(loginModel.Username, loginModel.Password); if (userResult.ResultCode != ResultCode.Success) { return(new Result <UserModel>(ResultCode.Unauthorized)); } var userModel = dataStructureConverter.Map <UserModel, User>(userResult.Data); userModel.Token = tokenManager.CreateToken(userModel); return(new Result <UserModel>(ResultCode.Success, userModel)); }
public async Task <IActionResult> Post([FromBody] LogEntryModel logEntryModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var log = dataStructureConverter.Map <LogEntry, LogEntryModel>(logEntryModel); var result = await logService.Log(log); if (result.ResultCode == ResultCode.Success) { return(Created(string.Empty, log.Message)); } return(errorCodeConverter.Convert(result.ResultCode)); }