public async Task <IActionResult> CreateActivityResearcher([FromBody] ActivityResearcher model) { if (!ModelState.IsValid) { return(new BadRequestObjectResult("Invalid model inputs")); } CreateActivityResearcherCommand command = new CreateActivityResearcherCommand(model); try { var result = await this._mediator.Send(command); if (result == null) { return(new BadRequestObjectResult("Something went wrong")); } if (result.GetType() == typeof(bool) && (bool)result == false) { return(new BadRequestObjectResult("Something went wrong")); } if (result.GetType() == typeof(string)) { return(new BadRequestObjectResult(result)); } return(new OkObjectResult(result)); } catch (Exception e) { throw; } }
public async Task <object> Handle(CreateActivityResearcherCommand request, CancellationToken cancellationToken) { try { ActivityResearcher uam = new ActivityResearcher(); uam.Created = DateTime.Now; uam.UserId = request.Model.UserId; uam.ActivityId = request.Model.ActivityId; uam.ResearcherId = request.Model.ResearcherId; var result = this._activityRepository.CreateActivityResearcher(uam); if (result == false) { this._unitOfWork.Rollback(); return(false); } this._unitOfWork.Commit(); this._unitOfWork.Dispose(); this._unitOfWork.QueueUserActivityLogItem(ActivityTypes.Activities.ActivityAddedToResearcher, uam.ActivityId); return(result); } catch (Exception e) { this._unitOfWork.Rollback(); this._unitOfWork.QueueErrorLogItem( ActivityTypes.Activities.ActivityAddedToResearcher, ActivityTypes.Areas.CreateActivityResearchHandler, e.Message); return(false); } }
public ReadAllActivityForResearcherHandlerTests() { _unitOfWork = new Mock <IUnitOfWork>(); _activityRepository = new Mock <IActivityRepository <Activity> >(); var activity1 = new ActivityResearcher() { ActivityId = 1, ResearcherId = 1, UserId = 1, Created = DateTime.Now, Id = 1 }; var activity2 = new ActivityResearcher() { ActivityId = 3, ResearcherId = 1, UserId = 1, Created = DateTime.Now, Id = 1 }; var activity3 = new ActivityResearcher() { ActivityId = 2, ResearcherId = 1, UserId = 1, Created = DateTime.Now, Id = 1 }; var activityList = new List <ActivityWithUserModel>(); ActivityWithUserModel activityWithUserModel = new ActivityWithUserModel() { ActivityName = "Tester1", Username = "******", Id = 1 }; ActivityWithUserModel activityWithUserModel1 = new ActivityWithUserModel() { ActivityName = "Tester2", Username = "******", Id = 2 }; ActivityWithUserModel activityWithUserModel2 = new ActivityWithUserModel() { ActivityName = "Tester3", Username = "******", Id = 3 }; listActivityWithUserModels = new List <ActivityWithUserModel>(); listActivityWithUserModels.Add(activityWithUserModel1); listActivityWithUserModels.Add(activityWithUserModel2); listActivityWithUserModels.Add(activityWithUserModel); }
public async void ReturnFalseIfBadInformation() { var tempActivityResearcher = new ActivityResearcher() { ActivityId = -1, Created = DateTime.Now, ResearcherId = -1, UserId = -1, Id = -1 }; _unitOfWork.Setup(mock => mock.ActivityRepository.CreateActivityResearcher(It.IsAny <ActivityResearcher>())) .Returns(false); var command = new CreateActivityResearcherCommand(tempActivityResearcher); var handler = new CreateActivityResearcherHandler(_unitOfWork.Object); var returnValue = await handler.Handle(command, new CancellationToken()); Assert.False((bool)returnValue); }
public bool CreateActivityResearcher(ActivityResearcher model) { try { string createActivityResearcher = "INSERT INTO EIC.dbo.ActivityResearcher (Created, ResearcherId, UserId, ActivityId) " + "VALUES (@Created, @ResearcherId, @UserId, @ActivityId); " + "SELECT SCOPE_IDENTITY();"; var result = this._connection.Execute(createActivityResearcher, model, this._transaction); if (result <= 0) { return(false); } return(true); } catch (Exception e) { return(false); } }
public CreateActivityResearcherCommand(ActivityResearcher model) { this.Model = model; }