public IHttpActionResult PostAttendee(DTO.Attendee attendee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var attendeeModel = attendee.ToModel(); attendeeModel.Name = attendeeModel.Name.Trim(); if (attendeeModel.CommunityGroupId == 0) { attendeeModel.CommunityGroupId = null; } _db.Attendees.Add(attendeeModel); _db.SaveChanges(); return(Ok(attendeeModel.Id)); }
public IHttpActionResult PutAttendee(int id, DTO.Attendee attendee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != attendee.Id) { return(BadRequest()); } var attendeeModel = attendee.ToModel(); attendeeModel.Name = attendeeModel.Name.Trim(); attendeeModel.IsDeleted = false; if (attendeeModel.CommunityGroupId == 0) { attendeeModel.CommunityGroupId = null; } _db.Entry(attendeeModel).State = EntityState.Modified; try { _db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AttendeeExists(id)) { return(NotFound()); } throw; } return(Ok()); }
public static Models.Attendee ToModel(this DTO.Attendee src) { return(Mapper.Map <Models.Attendee>(src)); }