// POST api/minutes
        public void Post(MinuteFullDTO minuteToAdd)
        {
            if (minuteToAdd == null)
                throw new HttpResponseException(HttpStatusCode.NoContent);

            //var response = new HttpResponseMessage();

            var minute = MinuteFullDTO.AsMinute(minuteToAdd);
            minute.Attendees = new Collection<Attendee>();

            foreach (var attendee in minuteToAdd.Attendees)
            {
                if (attendee.Id <= 0)
                    minute.Attendees.Add(AttendeeFullDTO.AsAttendee(attendee));
                else
                {
                    var attendeeFromDb = _unitOfWork.AttendeeRepository.GetById(attendee.Id);
                    if (attendeeFromDb != null)
                        minute.Attendees.Add(attendeeFromDb);
                }
            }

            _unitOfWork.MinutesRepository.AddMinute(minute);
            _unitOfWork.Commit();
        }
Example #2
0
 public static Minute AsMinute(MinuteFullDTO minuteFullDto, Minute minuteEntity)
 {
     minuteEntity.Id = minuteFullDto.Id;
     minuteEntity.Subject = minuteFullDto.Subject;
     minuteEntity.Date = minuteFullDto.Date;
     minuteEntity.Notes = minuteFullDto.Notes;
     return minuteEntity;
 }
        // PUT api/minutes/5
        public void Put(int id, MinuteFullDTO minuteToAdd)
        {
            if (minuteToAdd == null)
                throw new HttpResponseException(HttpStatusCode.NoContent);

            var minute = _unitOfWork.MinutesRepository.GetMinute(id);
            if (minute == null)
                throw new HttpResponseException(HttpStatusCode.NotFound);

            minute = MinuteFullDTO.AsMinute(minuteToAdd, minute);

            if (minute.Attendees == null)
                minute.Attendees = new Collection<Attendee>();

            foreach (var attendee in minuteToAdd.Attendees)
            {
                if (minute.Attendees.Any(i => i.Id == attendee.Id)) continue;

                if (attendee.Id <= 0)
                {
                    minute.Attendees.Add(AttendeeFullDTO.AsAttendee(attendee));
                    continue;
                }

                var attendeeFromDb = _unitOfWork.AttendeeRepository.GetById(attendee.Id);
                if (attendeeFromDb != null) minute.Attendees.Add(attendeeFromDb);

            }

            // Remove all not used anymore
            var allCurrentAttendeesIds = minuteToAdd.Attendees.Select(t => t.Id);
            minute.Attendees.Where(i => !allCurrentAttendeesIds.Contains(i.Id)).ToList()
                .ForEach(toDelete => minute.Attendees.Remove(toDelete));

            _unitOfWork.Commit();
        }
Example #4
0
 public static Minute AsMinute(MinuteFullDTO minuteFullDto)
 {
     return AsMinute(minuteFullDto, new Minute());
 }