Beispiel #1
0
        public void AddGuest(DTO.Guest newDTOGuest)
        {
            Guest newModelGuest = new Guest();

            convertToModelGuest(newDTOGuest, newModelGuest);
            try
            {
                using (var db = new GuestAppContext())
                {
                    var existingGuest = db.Guests.Find(newDTOGuest.Id);
                    if (existingGuest != null)
                    {
                        db.EventsGuests.Add(new EventGuest {
                            EventId = _currentEvent.Id, GuestId = newDTOGuest.Id
                        });
                    }
                    else
                    {
                        db.EventsGuests.Add(new EventGuest {
                            EventId = _currentEvent.Id, Guest = newModelGuest
                        });
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBoxError(ex.Message);
            }
        }
Beispiel #2
0
 public void DeleteGuestFromAllEvents(DTO.Guest SelectedGuest)
 {
     try
     {
         using (var db = new GuestAppContext())
         {
             var guestToDelete = db.Guests.Find(SelectedGuest.Id);
             db.Guests.Remove(guestToDelete);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBoxError(ex.InnerException.Message);
     }
 }
Beispiel #3
0
 public void RemoveGuestFromCurrentEvent(DTO.Guest selectedGuest)
 {
     try
     {
         using (var db = new GuestAppContext())
         {
             var guestToDelete = db.EventsGuests.SingleOrDefault(eg => eg.EventId == _currentEvent.Id && eg.GuestId == selectedGuest.Id);
             db.EventsGuests.Remove(guestToDelete);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBoxError(ex.InnerException.Message);
     }
 }
Beispiel #4
0
 public void DeleteEvent(Model.Event eventToDelete)
 {
     try
     {
         using (var db = new GuestAppContext())
         {
             var eventToRemove = db.Events.Find(eventToDelete.Id);
             db.Events.Remove(eventToRemove);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }
Beispiel #5
0
        public void EditEvent(DTO.Event eventToEdit, DTO.Event modifiedEvent)
        {
            try
            {
                using (var db = new GuestAppContext())
                {
                    var modelEvent = db.Events.Find(eventToEdit.Id);
                    modelEvent.Name = modifiedEvent.Name;
                    modelEvent.Date = modifiedEvent.Date;

                    db.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #6
0
        public void AddEvent(DTO.Event newEvent)
        {
            var modelEvent = Mapper.EventMapper(newEvent, new Model.Event());

            try
            {
                using (var db = new GuestAppContext())
                {
                    modelEvent.UserId = User.Id;
                    db.Events.Add(modelEvent);
                    db.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #7
0
 public void EditGuestDetails()
 {
     try
     {
         using (var db = new GuestAppContext())
         {
             var modelGuestToEdit = db.Guests.Find(UsersSelectedGuestToEdit.Id);
             convertToModelGuest(UsersSelectedGuestToEdit, modelGuestToEdit);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         var message = MessageBox.Show("There seems to be an error, make sure that there are no fields left empty!" +
                                       Environment.NewLine + ex.Message,
                                       "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
         throw;
     }
 }