public async Task <ActionResult> PostRequest(RequestCreateDto requestCreate) { try { var mappedmodel = mapper.Map <Request>(requestCreate); await requestsRepository.CreateRequestAsync(mappedmodel); await requestsRepository.SaveAsync(); var createdReadModel = mapper.Map <RequestReadDto>(mappedmodel); return(CreatedAtRoute(nameof(GetRequestById), new { createdReadModel.Id }, createdReadModel)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, new Response { Status = "Error", Message = ex.Message })); } }
public async Task <IHttpActionResult> Create(RequestCreateDto requestCreate) { if (ModelState.IsValid) { var session = await db.Sessions.SingleOrDefaultAsync( QueryHelper.GetSessionObjectValidationQuery(requestCreate.Session)); if (session != null) { var user = session.User; var selectedPlatforms = db.Platforms.Where(g => requestCreate.SelectedPlatforms.Contains(g.Id)) .ToList(); var new_request = new Request() { GameId = requestCreate.GameId, FilterType = requestCreate.FilterType, ReqMode = requestCreate.ReqMode, LocationCityId = requestCreate.LocationCity, LocationProvinceId = requestCreate.LocationProvince, LocationRegionId = requestCreate.LocationRegion, User = user, MaxPrice = requestCreate.MaxPrice, MinPrice = requestCreate.MinPrice, Platforms = selectedPlatforms, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, IsDeleted = false, }; db.Requests.Add(new_request); db.SaveChanges(); return(Ok(new_request.Id)); } return(Unauthorized()); } return(BadRequest()); }
public async Task <ActionResult> Put(int id, [FromBody] RequestCreateDto requestCreate) { try { var requestFromRepo = await requestsRepository.GetRequestAsync(id); if (requestFromRepo == null) { return(NotFound()); } var mappeedModel = mapper.Map(requestCreate, requestFromRepo); await requestsRepository.SaveAsync(); return(Ok(mappeedModel)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, new Response { Status = "Error", Message = ex.Message })); } }