public async Task <ActionResult <CampModels> > Post(CampModels model) { try { var monikerExits = await _campRepository.GetCampAsync(model.Moniker); if (monikerExits != null) { return(BadRequest("Moniker da ton tai")); } var camp = _mapper.Map <Camp>(model); _campRepository.Add(camp); if (await _campRepository.SaveChangesAsync()) { return(Created($"/api/camps/{model.Moniker}", _mapper.Map <CampModels>(camp))); } } catch (Exception) { return(this.StatusCode(500, "Database Failure")); } return(BadRequest()); }
public async Task <ActionResult <CampModels> > Put(string moniker, CampModels models) { try { var oldCamp = await _campRepository.GetCampAsync(moniker); if (oldCamp == null) { return(NotFound($"Moniker khong tim thay voi {moniker}")); } _mapper.Map(models, oldCamp); if (await _campRepository.SaveChangesAsync()) { return(_mapper.Map <CampModels>(oldCamp)); } } catch (Exception) { return(this.StatusCode(500, "Database Failure")); } return(BadRequest()); }
public async Task <ActionResult <CampModels> > Get(string moniker) { try { var result = await _campRepository.GetCampAsync(moniker); CampModels campModels = _mapper.Map <CampModels>(result); return(campModels); } catch (Exception) { return(this.StatusCode(500, "Database Failure")); } }
public async Task <ActionResult <CampModels> > GetById(int id, bool includeTalks = false) { try { var result = await campRepository.GetCampById(id, includeTalks); CampModels campModels = mapper.Map <CampModels>(result); return(campModels); } catch (Exception) { return(this.StatusCode(500, "Database Failure")); } }
public async Task <ActionResult <CampModels> > SearchByDate(DateTime theDate) { try { var result = await campRepository.GetAllCampsByEventDate(theDate); if (!result.Any()) { return(NotFound()); } CampModels campModels = mapper.Map <CampModels>(result); return(campModels); } catch (Exception) { return(this.StatusCode(500, "Database Failure")); } }