示例#1
0
 public static MeetingLocation ConvertToMeetingLocation(this MM_MeetingLocation meetingLocationDbModel)
 {
     return(new MeetingLocation()
     {
         Id = meetingLocationDbModel.Id,
         Name = meetingLocationDbModel.LocationName
     });
 }
        public MeetingLocation GetById(int id)
        {
            MM_MeetingLocation meetingLocationDbModel = _meetingDbContext.MM_MeetingLocations.FirstOrDefault(r => r.Id == id);

            if (meetingLocationDbModel == null)
            {
                throw new EntityNotFoundException <MeetingLocation>(id);
            }
            Console.WriteLine("Log Event got by id.");

            return(meetingLocationDbModel.ConvertToMeetingLocation());
        }
        public void Update(MeetingLocation meetingLocation)
        {
            MM_MeetingLocation meetingLocationDbModel = _meetingDbContext.MM_MeetingLocations.Find(meetingLocation.Id);

            if (meetingLocationDbModel == null)
            {
                throw new EntityNotFoundException <MeetingLocation>((int)meetingLocation.Id);
            }

            meetingLocationDbModel.LocationName = meetingLocation.Name;

            try
            {
                _meetingDbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new UpdateFailedException <MeetingLocation>((int)meetingLocation.Id);
            }
            Console.WriteLine("Log Event is Updated.");
        }
        public void Delete(int id)
        {
            MM_MeetingLocation meetingLocationDbModel = _meetingDbContext.MM_MeetingLocations.FirstOrDefault(x => x.Id == id);

            if (meetingLocationDbModel == null)
            {
                throw new EntityNotFoundException <MeetingLocation>(id);
            }

            _meetingDbContext.MM_MeetingLocations.Remove(meetingLocationDbModel);
            try
            {
                _meetingDbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new DeleteFailedException <MeetingLocation>(id);
            }


            Console.WriteLine("Log Event  is Deleted.");
        }
        public int Add(MeetingLocation meetingLocation)
        {
            MM_MeetingLocation meetingLocationDbModel = new MM_MeetingLocation()
            {
                LocationName = meetingLocation.Name
            };

            _meetingDbContext.MM_MeetingLocations.Add(meetingLocationDbModel);
            try
            {
                _meetingDbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new AddFailedException <MeetingLocation>();
            }


            Console.WriteLine("Log Item is Added.");

            return(meetingLocationDbModel.Id);
        }