public async Task <ActionResult <CampDTO> > Post(CampDTO campModel) { try { // Validation for dublicate moniker var campByMoniker = await _repo.GetCampAsync(campModel.Moniker); if (campByMoniker != null) { return(BadRequest("Camp with the Moniker already exists, please select a different Moniker")); } var location = _generator.GetPathByAction("Get", "Camp", new { moniker = campModel.Moniker }); if (string.IsNullOrWhiteSpace(location)) { return(BadRequest(" Moniker is invalid ")); } var camp = _mapper.Map <Camp>(campModel); _repo.Add(camp); if (await _repo.SaveChangesAsync()) { return(Created(location, _mapper.Map <CampDTO>(camp))); } } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "DB error")); } return(BadRequest()); }
public CampDTO GetCampEventDetails(int eventId) { var campEvent = _campService.GetCampEventDetails(eventId); var eligibleGradeGroups = campEvent.CampGradesList.Select(campGrade => new GroupDTO { GroupId = campGrade.GroupId, GroupName = campGrade.GroupName }).OrderBy(x => x.GroupName).ToList(); var campEventInfo = new CampDTO { EventId = campEvent.EventId, EventTitle = campEvent.EventTitle, EventType = campEvent.EventType, StartDate = campEvent.StartDate, EndDate = campEvent.EndDate, OnlineProductId = campEvent.OnlineProductId, RegistrationEndDate = campEvent.RegistrationEndDate, RegistrationStartDate = campEvent.RegistrationStartDate, ProgramId = campEvent.ProgramId, EligibleGradesList = eligibleGradeGroups, PrimaryContactEmail = campEvent.PrimaryContactEmail }; return(campEventInfo); }
public async Task <ActionResult <CampDTO> > Update(string moniker, CampDTO model) { try { var campToUpdate = await _repo.GetCampAsync(moniker); if (campToUpdate == null) { return(NotFound($"Camp with the moniker {moniker} does not exists!!!")); } _mapper.Map(model, campToUpdate); if (await _repo.SaveChangesAsync()) { return(_mapper.Map <CampDTO>(campToUpdate)); } } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "DB error")); } return(BadRequest(" Failed to update the Camp ")); }
public void PutCampById(int campId, CampDTO campDTO) { try { this.campBookingDAL.PutCampByIdDB(campId, campDTO); } catch (Exception e) { throw e; } }
public void PostNewCamp(CampDTO campDTO) { try { campBookingDAL.PostNewCampDB(campDTO); } catch (Exception e) { throw e; } }
/// <summary> /// Add camp /// </summary> /// <param name="camp"></param> /// <returns></returns> public HttpResponseMessage AddCamp([FromBody] CampDTO camp) { try { Icamp.AddCamp(camp); var message = Request.CreateResponse(HttpStatusCode.Created, camp); message.Headers.Location = new Uri(Request.RequestUri + camp.CampId.ToString()); return(message); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
/// <summary> /// Get camp by id /// </summary> /// <param name="id"></param> /// <returns></returns> public HttpResponseMessage GetCamp(int id) { CampDTO campViewModel = Icamp.GetCamp(id); if (campViewModel != null) { return(Request.CreateResponse(HttpStatusCode.OK, campViewModel)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No camp found with id " + id.ToString())); } }
// Post new Camp public void PostNewCampDB(CampDTO campDTO) { try { CampEntity campEntity = iMapper.Map <CampDTO, CampEntity>(campDTO); db.Camps.Add(campEntity); db.SaveChanges(); } catch (Exception e) { throw e; } }
public void PutCampByIdDB(int campId, CampDTO campDTO) { try { CampEntity campEntity = db.Camps.Find(campId); campEntity.CampName = campDTO.CampName; campEntity.Description = campDTO.Description; campEntity.Image = campDTO.Image; campEntity.ImageFile = campDTO.ImageFile; campEntity.RatePerNight = campDTO.RatePerNight; campEntity.MaxCapacity = campDTO.MaxCapacity; campEntity.ExtraWeekendCharges = campDTO.ExtraWeekendCharges; db.SaveChanges(); } catch (Exception e) { throw e; } }
/// <summary> /// Update camp Details /// </summary> /// <param name="id"></param> /// <param name="camp"></param> /// <returns></returns> public bool UpdateCamp(int id, CampDTO camp) { var entity = dBEntities.Camps.FirstOrDefault(c => c.CampId == id); if (entity == null) { return(false); } else { entity.Capacity = camp.Capacity; entity.Description = camp.Description; entity.Location = camp.Location; entity.Name = camp.Name; entity.Price = camp.Price; entity.Rating = camp.Rating; entity.ImageURL = camp.ImageURL; dBEntities.SaveChanges(); return(true); } }
public HttpResponseMessage UpdateCamp(int id, [FromBody] CampDTO camp) { try { if (id <= 0) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Not a valid camp id")); } else if (Icamp.UpdateCamp(id, camp) == false) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No camp found with id " + id.ToString())); } else { Icamp.UpdateCamp(id, camp); return(Request.CreateResponse(HttpStatusCode.OK, "1 row affected")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
/// <summary> /// Get camp by id /// </summary> /// <param name="id"></param> /// <returns></returns> public CampDTO GetCamp(int id) { CampDTO campViewModel = AutoMapper.Mapper.Map <CampDTO>(dBEntities.Camps.FirstOrDefault(myid => myid.CampId == id)); return(campViewModel); }
/// <summary> /// Add camp /// </summary> /// <param name="camp"></param> public void AddCamp(CampDTO camp) { dBEntities.Camps.Add(camp); dBEntities.SaveChanges(); }