예제 #1
0
 public MinutesOfMeetingDTO GetById(int minutesOfMeetingId)
 {
     try
     {
         MinutesOfMeetingDTO minutesOfMeeting = new MinutesOfMeetingDTO();
         Mapper.Map <Meeting, MinutesOfMeetingDTO>(_repository
                                                   .Query()
                                                   .Include(c => c.MeetingAttendances)
                                                   .SelectQueryable()
                                                   .Where(c => c.Id == minutesOfMeetingId).FirstOrDefault(), minutesOfMeeting);
         return(minutesOfMeeting);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #2
0
        public int Save(MinutesOfMeetingDTO obj, string currentUserId)
        {
            Meeting minutesOfMeeting;

            try
            {
                _unitOfWork.BeginTransaction();

                if (obj.Id == 0)
                {
                    minutesOfMeeting = new Meeting();
                    Mapper.Map <MinutesOfMeetingDTO, Meeting>(obj, minutesOfMeeting);
                    minutesOfMeeting.MeetingAttendances = new List <MeetingAttendance>();
                    if (obj.SelectedAttendances != null && obj.SelectedAttendances.Any())
                    {
                        foreach (int attendent in obj.SelectedAttendances)
                        {
                            minutesOfMeeting.MeetingAttendances.Add(new MeetingAttendance()
                            {
                                CouncilMemberId = attendent, IsAttendant = true, TrackingState = TrackableEntities.TrackingState.Added
                            });
                        }
                    }

                    if (obj.SelectedAbsents != null && obj.SelectedAbsents.Any())
                    {
                        foreach (int absent in obj.SelectedAbsents)
                        {
                            minutesOfMeeting.MeetingAttendances.Add(new MeetingAttendance()
                            {
                                CouncilMemberId = absent, IsAttendant = false, TrackingState = TrackableEntities.TrackingState.Added
                            });
                        }
                    }

                    //minutesOfMeeting.CreateDate = DateTime.Now;
                    minutesOfMeeting.CreatedBy = currentUserId;
                    base.Insert(minutesOfMeeting);
                }
                else
                {
                    minutesOfMeeting = new Meeting();
                    minutesOfMeeting = Mapper.Map <MinutesOfMeetingDTO, Meeting>(obj);
                    minutesOfMeeting.TrackingState = TrackableEntities.TrackingState.Modified;
                    base.Update(minutesOfMeeting);
                    var attendenceLst = _meetingAttendanceRepository.Query().Select().Where(c => c.MeetingId == obj.Id);
                    foreach (var s in attendenceLst)
                    {
                        _meetingAttendanceRepository.Delete(s.Id);
                    }
                    //InsertOrUpdateGraph(minutesOfMeeting);
                    _unitOfWork.SaveChanges();
                    if (obj.SelectedAttendances.Count > 0)
                    {
                        foreach (int attendent in obj.SelectedAttendances)
                        {
                            minutesOfMeeting.MeetingAttendances.Add(new MeetingAttendance()
                            {
                                CouncilMemberId = attendent, IsAttendant = true, TrackingState = TrackableEntities.TrackingState.Added
                            });
                        }
                    }

                    if (obj.SelectedAbsents.Count > 0)
                    {
                        foreach (int absent in obj.SelectedAbsents)
                        {
                            minutesOfMeeting.MeetingAttendances.Add(new MeetingAttendance()
                            {
                                CouncilMemberId = absent, IsAttendant = false, TrackingState = TrackableEntities.TrackingState.Added
                            });
                        }
                    }

                    minutesOfMeeting.LastUpdateDate = DateTime.Now;
                    minutesOfMeeting.LastUpdateBy   = currentUserId;
                    base.Update(minutesOfMeeting);
                }
                _unitOfWork.SaveChanges();
                _unitOfWork.Commit();
                return(minutesOfMeeting.Id);
            }
            catch (Exception)
            {
                throw;
            }
        }