/// <summary> /// Delete event - event category mapping /// </summary> /// <param name="eventId"></param> /// <param name="categoryId"></param> /// <returns></returns> public ResponseModel DeleteEventEventCategoryMapping(int eventId, int categoryId) { // Delete the Event Category mapping var response = _eventEventCategoryRepository.Delete(categoryId, eventId); return(response.SetMessage(response.Success ? T("EventEventCategory_Message_DeleteMappingSuccessfully") : T("EventEventCategory_Message_DeleteMappingFailure"))); }
/// <summary> /// Save event /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SaveEvent(EventManageModel model) { ResponseModel response; var item = GetById(model.Id); if (item != null) { item.Title = model.Title; item.EventSummary = model.EventSummary; item.EventDescription = model.EventDescription; item.MaxAttendees = model.MaxAttendees; item.RegistrationFullText = model.RegistrationFullText; item.RegistrationWaiver = model.RegistrationWaiver; response = Update(item); if (model.EventCategoryIds == null) { model.EventCategoryIds = new List <int>(); } var currentCategorys = item.EventEventCategories != null ? item.EventEventCategories.Select(t => t.EventCategoryId).ToList() : new List <int>(); var removedCategoryIds = currentCategorys.Where(id => !model.EventCategoryIds.Contains(id)); _eventEventCategoryRepository.Delete(item.Id, removedCategoryIds); var addedCategoryIds = model.EventCategoryIds.Where(id => !currentCategorys.Contains(id)); _eventEventCategoryRepository.Insert(item.Id, addedCategoryIds); response.SetMessage(response.Success ? T("Event_Message_UpdateSuccessfully") : T("Event_Message_UpdateFailure")); } else { Mapper.CreateMap <EventManageModel, Event>(); item = Mapper.Map <EventManageModel, Event>(model); response = Insert(item); if (response.Success) { if (model.EventCategoryIds != null) { foreach (var categoryId in model.EventCategoryIds) { var eventEventCategory = new EventEventCategory { EventCategoryId = categoryId, EventId = item.Id }; _eventEventCategoryRepository.Insert(eventEventCategory); } } } response.SetMessage(response.Success ? T("Event_Message_CreateSuccessfully") : T("Event_Message_CreateFailure")); } return(response); }