public ExcelImport(EventBusiness events, IEmailService emailService, IRazorPartialToStringRenderer renderer, UserBusiness userBusiness) { _events = events; _emailService = emailService; _renderer = renderer; _userBusiness = userBusiness; }
public async Task <IHttpActionResult> Get(long id, string appKey) { if (id == 0 || string.IsNullOrEmpty(appKey)) { return(BadRequest(Constants.HttpMessages.NoEntryWasPassed)); } try { Event eventEntry = await EventBusiness.GetByIdAsync(id, appKey); var eventResponse = Mapper.Map <EventResponseModel>(eventEntry); var response = new ApiResponse <EventResponseModel> { Message = string.Empty, Payload = eventResponse, StatusCode = Constants.ApiResponseCodes.OK }; return(Ok(response)); } catch (ArgumentException ax) { LogBuddy.LogError(ax); return(NotFound()); } catch (Exception ex) { LogBuddy.LogError(ex); return(InternalServerError(ex)); } }
public async Task <IHttpActionResult> Post(EventModel log) { if (log == null) { return(BadRequest(Constants.HttpMessages.NoEntryWasPassed)); } var response = new ApiResponse <long>(); try { var eventDto = Mapper.Map <Event>(log); Application app = await ApplicationBusiness.GetByAppKeyAsync(log.AppKey); eventDto.ApplicationId = app.Id; long registerEventResult = await EventBusiness.RegisterEventAsync(eventDto); eventDto.Id = registerEventResult; await RegisterChildEvents(log, eventDto.Id, eventDto.ApplicationId); response.Message = string.Empty; response.Payload = registerEventResult; string uri = Url.Link("GetEventRoute", new { id = registerEventResult, appKey = log.AppKey }); return(Created(uri, response)); } catch (Exception ex) { LogBuddy.LogError(ex); return(InternalServerError(ex)); } }
public void TestRemoveAllNullUserEventsFromTheDatabase() { EventBusiness mockEventBusiness = new EventBusiness(_mockContext.Object); User mockUser = null; Assert.Catch(() => mockEventBusiness.RemoveAllEvents(mockUser), "All null user events were removed!"); }
public void TestAddNullEventToTheDatabase() { EventBusiness mockEventBusiness = new EventBusiness(_mockContext.Object); Event mockEvent = null; Assert.Catch(() => mockEventBusiness.AddEvent(mockEvent), "Null event added to the database!"); }
public void TestFetchEventByIdWithNullUserFromTheDatabase() { EventBusiness mockEventBusiness = new EventBusiness(_mockContext.Object); int eventId = 5; User mockUser = null; Assert.Catch(() => mockEventBusiness.FetchEventById(eventId, mockUser), "Non existent event was fetched!"); }
public void TestFetchNonExistentEventByIdFromTheDatabase() { EventBusiness mockEventBusiness = new EventBusiness(_mockContext.Object); UserBusiness mockUserBusiness = new UserBusiness(_mockContext.Object); int eventId = 5; string userName = "******"; string passwordHash = "passwordHash"; User mockUser = mockUserBusiness.FetchUser(userName, passwordHash); Assert.Catch(() => mockEventBusiness.FetchEventById(eventId, mockUser), "Non existent event was fetched!"); }
public void TestAddNewEventToTheDatabase() { EventBusiness mockEventBusiness = new EventBusiness(_mockContext.Object); Event mockEvent = new Event() { EventId = 3, DueTime = DateTime.Now, Name = "name", UserId = 1 }; mockEventBusiness.AddEvent(mockEvent); Assert.Contains(mockEvent, mockEventBusiness.GetPODbContext.Events.ToList(), "Event not added properly!"); }
public void TestListAllUserEventsFromTheDatabase() { EventBusiness mockEventBusiness = new EventBusiness(_mockContext.Object); UserBusiness mockUserBusiness = new UserBusiness(_mockContext.Object); string userName = "******"; string passwordHash = "passwordHash"; User mockUser = mockUserBusiness.FetchUser(userName, passwordHash); int count = mockEventBusiness.ListAllEvents(mockUser).Count(); int expectedCount = mockEventBusiness.GetPODbContext.Events.Where(x => x.UserId == mockUser.UserId).ToList().Count(); Assert.AreEqual(expectedCount, count, "Not all events were fetched!"); }
public void TestFetchEventByIdFromTheDatabase() { EventBusiness mockEventBusiness = new EventBusiness(_mockContext.Object); UserBusiness mockUserBusiness = new UserBusiness(_mockContext.Object); int eventId = 1; string userName = "******"; string passwordHash = "passwordHash"; User mockUser = mockUserBusiness.FetchUser(userName, passwordHash); Event mockEvent = mockEventBusiness.FetchEventById(eventId, mockUser); Assert.AreEqual(eventId, mockEvent.EventId, "Wrong event was fetched!"); }
private async Task RegisterChildEvents(EventModel log, long id, long applicationId) { while (log.InnerEvent != null) { var eventDto = new Event(); Mapper.Map(log.InnerEvent, eventDto); eventDto.ApplicationId = applicationId; eventDto.ParentId = id; long newId = await EventBusiness.RegisterEventAsync(eventDto); log = log.InnerEvent; await RegisterChildEvents(log, newId, applicationId); } }
public async Task <ActionResult> AddAlert(AlertViewModel model) { if (model != null) { if (ModelState.IsValid) { if (!model.IncludesErrors && !model.IncludesFatals && !model.IncludesWarnings) { ModelState.AddModelError("Custom", "At least one type of event must be selected."); return(View(model)); } int eventLevelValue = 0; if (model.IncludesFatals) { eventLevelValue = (int)EventLevel.Fatal; } if (model.IncludesErrors) { eventLevelValue = eventLevelValue | (int)EventLevel.Error; } if (model.IncludesWarnings) { eventLevelValue = eventLevelValue | (int)EventLevel.Warning; } await EventBusiness.AddAlertAsync(new Alert { EventLevelValue = eventLevelValue, PeriodValue = model.PeriodValue, Target = model.Target, TypeOfPeriod = (PeriodType)model.TypeOfPeriod, TypeOfNotification = (NotificationType)model.TypeOfNotification, Value = model.Value, AppId = model.AppId }); return(RedirectToAction("ViewAlerts", new { appId = model.AppId })); } return(View(model)); } ModelState.AddModelError("Custom", "Invalid model was passed."); return(View(new AlertViewModel())); }
public async Task <ActionResult> GetEvent(long id, string appKey) { try { Event eventEntry = await EventBusiness.GetByIdAsync(id, appKey); return(PartialView("EventDetails", eventEntry)); } catch (Exception ex) { Logger.LogError(ex); return(new ContentResult { Content = "An error occured." }); } }
public void TestDeleteEventFromTheDatabase() { EventBusiness mockEventBusiness = new EventBusiness(_mockContext.Object); UserBusiness mockUserBusiness = new UserBusiness(_mockContext.Object); int eventId = 1; string userName = "******"; string passwordHash = "passwordHash"; int oldCount = mockEventBusiness.GetPODbContext.Events.ToList().Count(); User mockUser = mockUserBusiness.FetchUser(userName, passwordHash); mockEventBusiness.RemoveEvent(eventId, mockUser); Assert.Less(mockEventBusiness.GetPODbContext.Events.ToList().Count(), oldCount, "Event not deleted properly!"); }
private void Dispose(bool dispose) { if (dispose) { if (_departmentBusiness != null) { //_connection.Dispose(); _departmentBusiness = null; } if (_archiveBusiness != null) { _archiveBusiness = null; } if (_eventBusiness != null) { _eventBusiness = null; } if (_imageBusiness != null) { _imageBusiness = null; } if (_imgPhotoGalleryBusiness != null) { _imgPhotoGalleryBusiness = null; } if (_photoGalleryBusiness != null) { _photoGalleryBusiness = null; } if (_videoBusiness != null) { _videoBusiness = null; } if (_repositoryContext != null) { _repositoryContext.Dispose(); _repositoryContext = null; } if (_instance != null) { _instance = null; } } }
/// <summary> /// Constructeur principal /// </summary> public EventService() { _Business = new EventBusiness(); }