public bool Delete(int id) { // If this constituent is in the call assignments, remove them from there before deleting CallAssignment callAssignment = unitOfWork.Assignments.Get(id); if (callAssignment != null) { unitOfWork.Assignments.Remove(callAssignment); // Remove the constituent from the database Constituent constituent = unitOfWork.Constituents.Find(x => x.ConstituentID == id).FirstOrDefault(); if (constituent != null) { unitOfWork.Constituents.Remove(constituent); unitOfWork.Complete(); } return(true); } else { // Remove the constituent from the database Constituent constituent = unitOfWork.Constituents.Find(x => x.ConstituentID == id).FirstOrDefault(); if (constituent != null) { unitOfWork.Constituents.Remove(constituent); unitOfWork.Complete(); } return(true); } }
public void MapModelToEntity() { var mapper = new DALCallAssignmentMapper(); ApiCallAssignmentServerRequestModel model = new ApiCallAssignmentServerRequestModel(); model.SetProperties(1, 1); CallAssignment response = mapper.MapModelToEntity(1, model); response.CallId.Should().Be(1); response.UnitId.Should().Be(1); }
public void MapEntityToModel() { var mapper = new DALCallAssignmentMapper(); CallAssignment item = new CallAssignment(); item.SetProperties(1, 1, 1); ApiCallAssignmentServerResponseModel response = mapper.MapEntityToModel(item); response.CallId.Should().Be(1); response.Id.Should().Be(1); response.UnitId.Should().Be(1); }
public void MapEntityToModelList() { var mapper = new DALCallAssignmentMapper(); CallAssignment item = new CallAssignment(); item.SetProperties(1, 1, 1); List <ApiCallAssignmentServerResponseModel> response = mapper.MapEntityToModel(new List <CallAssignment>() { { item } }); response.Count.Should().Be(1); }
public virtual async Task <ApiCallAssignmentServerResponseModel> Get(int id) { CallAssignment record = await this.CallAssignmentRepository.Get(id); if (record == null) { return(null); } else { return(this.DalCallAssignmentMapper.MapEntityToModel(record)); } }
public virtual CallAssignment MapModelToEntity( int id, ApiCallAssignmentServerRequestModel model ) { CallAssignment item = new CallAssignment(); item.SetProperties( id, model.CallId, model.UnitId); return(item); }
public virtual async Task <CreateResponse <ApiCallAssignmentServerResponseModel> > Create( ApiCallAssignmentServerRequestModel model) { CreateResponse <ApiCallAssignmentServerResponseModel> response = ValidationResponseFactory <ApiCallAssignmentServerResponseModel> .CreateResponse(await this.CallAssignmentModelValidator.ValidateCreateAsync(model)); if (response.Success) { CallAssignment record = this.DalCallAssignmentMapper.MapModelToEntity(default(int), model); record = await this.CallAssignmentRepository.Create(record); response.SetRecord(this.DalCallAssignmentMapper.MapEntityToModel(record)); await this.mediator.Publish(new CallAssignmentCreatedNotification(response.Record)); } return(response); }
public async void Get_ShouldReturnRecords() { var mock = new ServiceMockFacade <ICallAssignmentService, ICallAssignmentRepository>(); var record = new CallAssignment(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record)); var service = new CallAssignmentService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.CallAssignmentModelValidatorMock.Object, mock.DALMapperMockFactory.DALCallAssignmentMapperMock); ApiCallAssignmentServerResponseModel response = await service.Get(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public virtual ApiCallAssignmentServerResponseModel MapEntityToModel( CallAssignment item) { var model = new ApiCallAssignmentServerResponseModel(); model.SetProperties(item.Id, item.CallId, item.UnitId); if (item.CallIdNavigation != null) { var callIdModel = new ApiCallServerResponseModel(); callIdModel.SetProperties( item.CallIdNavigation.Id, item.CallIdNavigation.AddressId, item.CallIdNavigation.CallDispositionId, item.CallIdNavigation.CallStatusId, item.CallIdNavigation.CallString, item.CallIdNavigation.CallTypeId, item.CallIdNavigation.DateCleared, item.CallIdNavigation.DateCreated, item.CallIdNavigation.DateDispatched, item.CallIdNavigation.QuickCallNumber); model.SetCallIdNavigation(callIdModel); } if (item.UnitIdNavigation != null) { var unitIdModel = new ApiUnitServerResponseModel(); unitIdModel.SetProperties( item.UnitIdNavigation.Id, item.UnitIdNavigation.CallSign); model.SetUnitIdNavigation(unitIdModel); } return(model); }
public virtual async Task <UpdateResponse <ApiCallAssignmentServerResponseModel> > Update( int id, ApiCallAssignmentServerRequestModel model) { var validationResult = await this.CallAssignmentModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { CallAssignment record = this.DalCallAssignmentMapper.MapModelToEntity(id, model); await this.CallAssignmentRepository.Update(record); record = await this.CallAssignmentRepository.Get(id); ApiCallAssignmentServerResponseModel apiModel = this.DalCallAssignmentMapper.MapEntityToModel(record); await this.mediator.Publish(new CallAssignmentUpdatedNotification(apiModel)); return(ValidationResponseFactory <ApiCallAssignmentServerResponseModel> .UpdateResponse(apiModel)); } else { return(ValidationResponseFactory <ApiCallAssignmentServerResponseModel> .UpdateResponse(validationResult)); } }
public JsonResult UpdateCallerAssignments(BlockCallAssignmentsModel model) { // Ensure the model is in a valid state before doing anything with it if (ModelState.IsValid) { // Iterate over each entry of the array of Constituent IDs foreach (var constituentID in model.Constituents) { // Get the Call Assignment associated with the current constituentID by ConstituentID CallAssignment assignmentToUpdate = unitOfWork.Assignments.Find(x => x.ConstituentID == constituentID).FirstOrDefault(); //assignments.Where(x => x.ConstituentID == constituentID).FirstOrDefault(); // Quick compare of the current CallerID -- not sure if this is beneficial at all if (assignmentToUpdate.CallerID != model.CallerID) { // Remove the entry associated with this Call Assignment -- necessary to avoid constraint issues unitOfWork.Assignments.Remove(assignmentToUpdate); // Create a new CallAssignment, updating the CallerID to the new one -- other values stay the same CallAssignment updatedCallAssignment = new CallAssignment() { CallerID = model.CallerID, Constituent = unitOfWork.Constituents.Find(x => x.ConstituentID == constituentID).FirstOrDefault(), ConstituentID = constituentID }; // Add the updated version of this Call Assignment back into the table unitOfWork.Assignments.Add(updatedCallAssignment); } } // Save the changes unitOfWork.Complete(); } // Return an empty JSON object -- we don't care about what's returned, only that *something* is returned return(Json(model, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Removes a Call Assigment associated with the given Constituent ID. /// </summary> /// <param name="id">The ID of the Constituent whos Call Assignment we want to remove</param> /// <returns>The view with the user's Call Assignments on success, Error view otherwise.</returns> public virtual ActionResult RemoveCallAssignment(int?id) { // Check if the id passed in is null if (id != null) { // Look up this Constituent using the given ID, and check if it's null Constituent constituent = unitOfWork.Constituents.Find(x => x.ConstituentID == id).FirstOrDefault(); if (constituent != null) { // Lookup the Call Assignment associated with this Constituent, and check if it's null CallAssignment assignment = unitOfWork.Assignments.Find(x => x.ConstituentID == id).FirstOrDefault(); if (assignment != null) { // Remove the call assignment from the database, and save the changes unitOfWork.Assignments.Remove(assignment); unitOfWork.Complete(); return(View("ViewCallList")); } } } return(View("Error")); }
public ActionResult GetNextCallAssignment(int?id, string donationType, string callOutcome) { // If the id passed in is null for any reason, return the user to their Call List if (id == null) { return(RedirectToAction("ViewCallList", "StandardUsers")); } // Check if user input has been given on potential donation type if (!string.IsNullOrEmpty(donationType) || !string.IsNullOrEmpty(callOutcome)) { // Create a new gift entry var update = new Gift { Constituent = db.Constituents.Find(id), CallLog = new CallLog() }; // Get the currently logged in user var user = User.Identity.GetUserId(); //////////////////////////////////////////////////////// // // // Fill in the relevant attributes of the call record // // // //////////////////////////////////////////////////////// // Set the Caller and Constituent IDs update.CallLog.CallerID = user; update.CallLog.ConstituentID = id.GetValueOrDefault(); // Set the date of the call DateTime dateOnly = DateTime.Now; update.CallLog.DateOfCall = dateOnly.Date; // Set CallAnswered and LineAvailable update.CallLog.CallAnswered = true; update.CallLog.LineAvailable = true; // Assign the gift type if (!string.IsNullOrEmpty(donationType)) { update.GiftType = donationType; } else { update.GiftType = null; } // Assign the call outcome if (!string.IsNullOrEmpty(callOutcome)) { update.CallLog.CallOutcome = callOutcome; } else { update.CallLog.CallOutcome = null; } // Deal with GiftAmount and Gift recipient later // Add the Gift and CallLog to the database, then save the changes db.Gifts.Add(update); db.CallLogs.Add(update.CallLog); db.SaveChanges(); } // Find and remove the Call Assignment that was just completed, and save the changes var userID = User.Identity.GetUserId(); // Attempt to grab the next Call Assignment var remainingAssignments = db.CallAssignments.Where(c => c.CallerID == userID).ToList(); Constituent nextConstituent = new Constituent(); // Make sure there's actually another Call Assignment if (remainingAssignments != null && remainingAssignments.Count > 0) { // Two or more Call Assignments remaining for this user if (remainingAssignments.Count >= 2) { CallAssignment nextCall = remainingAssignments.ElementAt(1); nextConstituent = nextCall.Constituent; } // Exactly one Call Assignment remaining for this user else if (remainingAssignments.Count == 1) { CallAssignment nextCall = remainingAssignments.ElementAt(0); nextConstituent = nextCall.Constituent; } // There are no more Call Assigments for this user -- redirect to their empty Call List view else { return(RedirectToAction("ViewCallList", "StandardUsers")); } } // There are no more Call Assigments for this user -- redirect to their empty Call List view else { return(RedirectToAction("ViewCallList", "StandardUsers")); } // Build lists of Call Logs and Gifts to display in the view ViewBag.CallLog = db.CallLogs.Where(x => x.ConstituentID == id).OrderBy(x => x.DateOfCall).ToList(); ViewBag.Gifts = db.Gifts.Where(x => x.ConstituentID == id).OrderBy(x => x.CallLog.DateOfCall).ToList(); // Return to the view with the next Constituent loaded return(View("Index", nextConstituent)); }