Esempio n. 1
0
        public IHttpActionResult GetMeeting(int id)
        {
            var m = db.Meetings.Include(x => x.Attendees).Include(x => x.CommunityGroup).SingleOrDefault(x => x.Id == id);

            if (m == null)
            {
                return(NotFound());
            }

            var rv = new DTO.Meeting
            {
                Id = m.Id,
                CommunityGroupId = m.CommunityGroupId,
                Date             = m.Date,
                Attendees        = new List <DTO.Attendee>
                                   (
                    m.Attendees.Select(a => new DTO.Attendee
                {
                    Id       = a.Id,
                    Name     = a.Name,
                    IsMember = a.IsMember
                })
                                   ),
                CommunityGroup = new DTO.CommunityGroup
                {
                    Id       = m.CommunityGroupId,
                    Name     = m.CommunityGroup.Name,
                    LeaderId = m.CommunityGroup.LeaderId
                }
            };

            return(Ok(rv));
        }
Esempio n. 2
0
        public IHttpActionResult PostMeeting(DTO.Meeting meeting)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var model = Mapper.Map <Meeting>(meeting);

            model.Attendees.Clear();
            // for existing attendees, don't create new entries
            foreach (var a in meeting.Attendees.Where(x => x.Id > 0))
            {
                model.Attendees.Add(db.Attendees.FirstOrDefault(x => x.Id == a.Id));
            }

            foreach (var a in meeting.Attendees.Where(x => x.Id == 0))
            {
                model.Attendees.Add(a.ToModel());
            }
            model.Date = model.Date.Date;
            db.Meetings.Add(model);
            db.SaveChanges();

            return(Ok(model.Id));
        }
Esempio n. 3
0
        public IHttpActionResult PutMeeting(int id, DTO.Meeting meeting_vm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != meeting_vm.Id)
            {
                return(BadRequest());
            }

            _logger.Info("Meeting update: " + meeting_vm.ToJson());

            var origModel = db.Meetings.Include(c => c.Attendees).Single(x => x.Id == id);

            db.Entry(origModel).CurrentValues.SetValues(meeting_vm);

            // remove any attendees no longer in attendee list from orig db obj
            foreach (var oa in origModel.Attendees.ToList())
            {
                if (meeting_vm.Attendees.All(a => a.Id != oa.Id))
                {
                    _logger.Trace($"deleting attendee {oa.Id} from meeting {meeting_vm.Id}");
                    origModel.Attendees.Remove(oa);
                }
            }

            // add all new attendees
            foreach (var na in meeting_vm.Attendees)
            {
                if (origModel.Attendees.All(a => a.Id != na.Id))
                {
                    if (na.Id > 0)
                    {
                        origModel.Attendees.Add(db.Attendees.FirstOrDefault(x => x.Id == na.Id));
                    }
                    else
                    {
                        var newAttendee = Mapper.Map <Attendee>(na);
                        newAttendee.Name = newAttendee.Name.Trim();
                        origModel.Attendees.Add(newAttendee);
                    }
                }
            }

            db.SaveChanges();

            return(Ok());
        }
Esempio n. 4
0
 public static Models.Meeting ToModel(this DTO.Meeting src)
 {
     return(Mapper.Map <Models.Meeting>(src));
 }
Esempio n. 5
0
 public static DAL.meeting Convert(DTO.Meeting dto)
 {
     return(_mapper.Map <DAL.meeting>(dto));
 }