public async Task <IHttpActionResult> AddDesicion([FromBody] InspectionDto dto) { var qualityControl = await _unitOfWork.QualityControlRepository.FindByIdAsync(dto.QualityControlId); var desicion = await _unitOfWork.DesicionRepository.FindByIdAsync(dto.Desicion); if (qualityControl == null) { return(NotFound()); } if (desicion == null) { return(BadRequest()); } try { var user = await GetUserAsync(); var inspection = _factory.Create(dto, user); inspection.Desicion = desicion; qualityControl.SetInspection(inspection, user); await _unitOfWork.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok()); }
public void PostDuplicateInspection_ShouldReturnFound() { var newInspectionModel = new InspectionDto { MethodSetId = "Method_Set_Id", StartTime = DateTime.Now - TimeSpan.FromMinutes(7), InspectionPlace = InspectionPlace.OnWorkplace, InspectionType = InspectionType.PreShift, EmployeeId = _gryffindorEmployees.First().Id, MachineName = "HOST002", MethodSetVersion = "Version 16" }; // When // a duplicate exception is posted var response1 = _httpClient.PostAsJsonAsync(_url, newInspectionModel).Result; var response2 = _httpClient.PostAsJsonAsync(_url, newInspectionModel).Result; // Then // the 2nd result is 'Found' with a link to the existing inspection Assert.That(response1.StatusCode, Is.EqualTo(HttpStatusCode.Created)); Assert.That(response2.StatusCode, Is.EqualTo(HttpStatusCode.Found)); var newEntityInfo = response1.Content.ReadAsJsonAsync<PskOnline.Client.Api.Models.CreatedWithGuidDto>().Result; Assert.IsTrue(response2.Headers.Location.ToString().EndsWith(newEntityInfo.Id.ToString())); }
public Inspection Create(InspectionDto dto, User user) { return(new Inspection(user) { Comments = dto.Comments }); }
private async Task SeedTestInspections(IApiClient apiClient) { { await apiClient.AsGryffindorAdminAsync(_httpClient); var newEmployee = new EmployeeDto { FirstName = "John", LastName = "Doe", Patronymic = "Alan", PositionId = _gryffindorHouse.Position_Default.Id, DepartmentId = _gryffindorHouse.Department_1_1.Department.Id, BranchOfficeId = _gryffindorHouse.BranchOffice_One.Id }; var employeeId = await apiClient.PostEmployeeAsync(newEmployee); var gryInspection = new InspectionDto { Id = Guid.NewGuid().ToString(), MethodSetId = "Method_Set_Id", StartTime = DateTime.Now - TimeSpan.FromMinutes(700), FinishTime = DateTime.Now - TimeSpan.FromMinutes(700), InspectionPlace = InspectionPlace.OnWorkplace, InspectionType = InspectionType.PreShift, EmployeeId = employeeId.ToString(), MachineName = "HOST002-gry", MethodSetVersion = "Version 16" }; _gryffindorInspectionId = await PostManyInspections(apiClient, gryInspection); } { await apiClient.AsSlytherinAdminAsync(_httpClient); var newEmployee = new EmployeeDto { FirstName = "John", LastName = "Doe", Patronymic = "Alan", PositionId = _slytherinHouse.Position_Default.Id, DepartmentId = _slytherinHouse.Department_1_1.Department.Id, BranchOfficeId = _slytherinHouse.BranchOffice_One.Id }; var employeeId = await apiClient.PostEmployeeAsync(newEmployee); var slyInspection = new InspectionDto { Id = Guid.NewGuid().ToString(), MethodSetId = "Method_Set_Id", StartTime = DateTime.Now - TimeSpan.FromMinutes(700), FinishTime = DateTime.Now - TimeSpan.FromMinutes(700), InspectionPlace = InspectionPlace.OnWorkplace, InspectionType = InspectionType.PreShift, EmployeeId = employeeId.ToString(), MachineName = "HOST002-sly", MethodSetVersion = "Version 16" }; _slytherinInspectionId = await PostManyInspections(apiClient, slyInspection); } }
public void CreateMission(InspectionDto input) { var task = Mapper.Map <Inspection>(input); task.Id = null; task.Inspection_No = Snowflake.Instance().GetId(); _Inspectionrepository.Insert(task); }
public BillInfoDto GetMissionById(long taskId) { var HasI = PermissionChecker.IsGranted(PermissionNames.Pages_Inspection); //判断是有权限 var task = _BillInfoRepository.FirstOrDefault(t => t.Id == taskId); if (HasI == true) //有审核权限则直接查看所有 { return(Mapper.Map <BillInfoDto>(task)); } else { if (task.BillStateID < 2) { return(Mapper.Map <BillInfoDto>(task)); } else //若货单状态为已签收,则发起查看申请到审核表 { //若状态为已签收,且已经发起申请,且申请通过,则可以直接查看 var tasks = _Inspectionrepository.GetAll() .Where(t => t.IsCandidate == true && t.InspectionState == 1 && taskId == t.SourceNo).ToList(); if (tasks.Count > 0) { return(Mapper.Map <BillInfoDto>(task)); } else { #region MyRegion InspectionDto inspectionDto = new InspectionDto { Id = null, Inspection_No = Snowflake.Instance().GetId(), SourceType = "货票", SourceNo = task.Id, StartDate = DateTime.UtcNow, DestinationNO = task.Id, Version = 1, ProposerName = "", ProposerID = 11, //AbpSession.GetUserId(), Title = "货票 查看", IsCandidate = true, InspectionState = 0, InspectionName = null, Action = "查看", InspectionMemo = "", EndDate = null, Quality_level = 1 }; var inspection = Mapper.Map <Inspection>(inspectionDto); _Inspectionrepository.Insert(inspection); #endregion return(null); } } } }
public string UpdateMission(CustomerInfoDto input) { #region 修改信息处理 // input.Id =null; //分布式ID作为主键 var result = Mapper.Map <CustomerInfo>(input); result.UpVersion(); //版本号加一 result.ChangeIsCandidate(); //设为候选待审核 _CustomerinfoRepository.Insert(result); CurrentUnitOfWork.SaveChanges(); #endregion #region 检查是否有同货票号且正在生效中信息 var task = _CustomerinfoRepository.GetAll() .Where(t => t.CustomerID == input.CustomerID && t.IsCandidate == false); #endregion // if (input.State == 1)//审核时提出修改信息,新增同货票号新信息,未审核通过时 IsCandidate 状态为1(未审核),同时生成对应审核表内容 if (task.ToList().Count <= 0) { return("该货票基本信息已被删除,不能提出修改"); } //原基本信息不存在,不能修改 else { #region 审核信息新建 InspectionDto inspectionDto = new InspectionDto { Id = null, Inspection_No = Snowflake.Instance().GetId(), SourceType = "客户", SourceNo = Convert.ToInt64(task.FirstOrDefault().Id), StartDate = DateTime.UtcNow, DestinationNO = Convert.ToInt64(result.Id), Version = 1, ProposerName = "", ProposerID = AbpSession.GetUserId(), Title = "客户 修改", IsCandidate = true, InspectionState = 0, InspectionName = null, Action = "修改", InspectionMemo = "", EndDate = null, Quality_level = 1 }; var inspection = Mapper.Map <Inspection>(inspectionDto); _Inspectionrepository.Insert(inspection); #endregion return("提出修改成功"); } }
public long?CreateMissionQ(InspectionDto input) { var task = Mapper.Map <Inspection>(input); task.Id = null; // long NO = ShortSnowflake.Instance().GetId(); var result = _Inspectionrepository.Insert(task); CurrentUnitOfWork.SaveChanges(); return(result.Id); }
public string DeleteMission_admin(long taskId) { var HasI = PermissionChecker.IsGranted(PermissionNames.Pages_Inspection); //判断是否有审核权限 var task = _BillInfoRepository.FirstOrDefault(t => t.Id == taskId && t.IsCandidate == false); if (HasI) { try { var result = Mapper.Map <BillInfo>(task); if (task != null) { _BillInfoRepository.Delete(result); return("删除成功"); } else { return("资料不存在"); } } catch { return("删除失败"); } } else { #region 审核信息新建 InspectionDto inspectionDto = new InspectionDto { Id = null, Inspection_No = Snowflake.Instance().GetId(), SourceType = "货票", SourceNo = task.Id, StartDate = DateTime.UtcNow, DestinationNO = task.Id, Version = 1, ProposerName = "", ProposerID = AbpSession.GetUserId(), Title = "货票 删除", IsCandidate = true, InspectionState = 0, InspectionName = null, Action = "删除", InspectionMemo = "", EndDate = null, Quality_level = 1 }; var inspection = Mapper.Map <Inspection>(inspectionDto); _Inspectionrepository.Insert(inspection); #endregion return("已提出删除申请"); } }
/// <summary> /// /// </summary> /// <param name="apiClient"></param> /// <param name=""></param> private async Task<Guid> PostManyInspections(IApiClient apiClient, InspectionDto template) { var fiveMinutes = TimeSpan.FromMinutes(5); var lastInspectionId = Guid.Empty; var oneHundredKbytes = new string('X', 150*1024); for (int i = 0; i < 25; i++) { try { // add more inspections to test paging options var newInspection = Mapper.Map<InspectionDto>(template); newInspection.Id = Guid.NewGuid().ToString(); newInspection.EmployeeId = template.EmployeeId; newInspection.StartTime = DateTime.Now - TimeSpan.FromMinutes(i * 10); newInspection.FinishTime = null; var test = new TestDto { Id = Guid.NewGuid().ToString(), MethodId = "123", MethodVersion = "1.0", InspectionId = newInspection.Id, EmployeeId = newInspection.EmployeeId, StartTime = newInspection.StartTime, FinishTime = newInspection.StartTime + fiveMinutes, MethodProcessedDataJson = JObject.Parse("{}"), MethodRawDataJson = JObject.Parse("{ \"value\" : \"" + oneHundredKbytes + "\"}") }; lastInspectionId = await apiClient.PostInspectionAsync(newInspection); Console.WriteLine($"posted {i}-th inspection"); test.InspectionId = lastInspectionId.ToString(); await apiClient.PostTestAsync(test); await apiClient.CompleteInspectionAsync(new InspectionCompleteDto { Id = lastInspectionId, FinishTime = newInspection.StartTime + fiveMinutes }); } catch (Exception ex) { Console.WriteLine($"Failed to post {i}-th inspection: {ex.Message}"); throw; } } return lastInspectionId; }
public async Task <InspectionDto> CreateInspectionAsync(InspectionDto createDto) { var vehicle = _dbContext.Vehicles.SingleOrDefault(v => v.Id == createDto.VehicleId); if (vehicle == null) { throw new ArgumentException("A valid vehicle entry is required!"); } var inspection = new Inspection(createDto.InspectorName, createDto.InspectionLocation, createDto.InspectionDate, vehicle); _dbContext.Inspections.Add(inspection); await _dbContext.SaveChangesAsync(); return(MapToDto(inspection)); }
public void UpdateOwnTenantInspection_ShouldFail_GivenInspectionIsCompleted() { // Given // an infrastructure with tenants and client authorized as Gryffindor House user var updatedGryffindorInspection = new InspectionDto { Id = _gryffindorInspectionId.ToString() }; updatedGryffindorInspection.FinishTime = DateTime.Now; // When // the user attempts to update an inspection within Gryffindor House var putResponse = _httpClient.PutAsJsonAsync(_url + updatedGryffindorInspection.Id.ToString(), updatedGryffindorInspection); // Then // The server responds with 'Method Not Allowed' Assert.That(putResponse.Result.StatusCode, Is.EqualTo(HttpStatusCode.MethodNotAllowed)); }
public async Task <InspectionDto> UpdateVehicleInspection(InspectionDto updateDto) { var inspection = _dbContext.Inspections .SingleOrDefault(i => i.Id == updateDto.Id); if (inspection == null) { throw new ArgumentException($"Vehicle inspection entry could not exists!"); } inspection.UpdateResult(updateDto.DidTestPass); inspection.UpdateInspector(updateDto.InspectorName); inspection.UpdateLocation(updateDto.InspectionLocation); inspection.UpdateNotes(updateDto.InspectionNotes); inspection.SetDate(updateDto.InspectionDate); await _dbContext.SaveChangesAsync(); return(MapToDto(inspection)); }
protected override void InitializeMockData() { desicion = new Desicion { Id = 1, Name = "Acepted" }; inspection = new InspectionDto { QualityControlId = 1, Comments = "Instructions' results OK", Desicion = 1 }; control = new QualityControl { Name = "High tolerances", Defect = new Defect { Name = "Dimensional" }, Status = QualityControlStatus.Open }; }
public Inspection AddNewInspection(InspectionDto newInspection) { var inspection = new Inspection() { CompanyId = newInspection.CompanyId, Description = newInspection.Description, Reviews = newInspection.Reviews.Select(review => new Review() { Comment = review.Comment, Question = review.Question, Score = review.Score }).ToList(), Responsible = newInspection.Responsible.Select(r => new InspectionResponsible() { ResponsibleId = r.ResponsibleId }).ToList() }; _context.Inspections.Add(inspection); _context.SaveChanges(); return(inspection); }
public void InspectionDto_To_Inspection() { var newInspectionModel = new InspectionDto { MethodSetId = "Method_Set_Id", StartTime = DateTime.Now - TimeSpan.FromMinutes(7), FinishTime = DateTime.Now, InspectionPlace = InspectionPlace.OnWorkplace, InspectionType = InspectionType.PreShift, EmployeeId = Guid.NewGuid().ToString(), BranchOfficeId = Guid.NewGuid().ToString(), DepartmentId = Guid.NewGuid().ToString(), MachineName = "HOST002", MethodSetVersion = "Version 16" }; var inspection = Mapper.Map <Inspection>(newInspectionModel); var inspectionDto = Mapper.Map <InspectionDto>(inspection); }
public void PostInspection_ShouldSucceed() { var newInspectionModel = new InspectionDto { MethodSetId = "Method_Set_Id", StartTime = DateTime.Now - TimeSpan.FromMinutes(7), InspectionPlace = InspectionPlace.OnWorkplace, InspectionType = InspectionType.PreShift, EmployeeId = _gryffindorEmployees.First().Id, MachineName = "HOST002", MethodSetVersion = "Version 16" }; var response = _httpClient.PostAsJsonAsync(_url, newInspectionModel); Assert.That(response.Result.StatusCode, Is.EqualTo(HttpStatusCode.Created)); var createdEntityInfo = response.Result.Content.ReadAsJsonAsync<PskOnline.Client.Api.Models.CreatedWithGuidDto>().Result; var verifyResponse = _httpClient.GetAsync(_url + createdEntityInfo.Id.ToString()); var verifyContent = verifyResponse.Result.Content; var verifyInspection = verifyContent.ReadAsJsonAsync<InspectionDto>().Result; Assert.That(verifyInspection.MachineName, Is.EqualTo(newInspectionModel.MachineName)); Assert.That(verifyInspection.Id, Is.EqualTo(createdEntityInfo.Id.ToString())); }
public void BeginInspection_Should_Call_BeginInspectionAsync_And_Return_Created_() { // Given var controller = new InspectionController(_inspectionService, _tenantIdProvider); var newInspectionModel = new InspectionDto { MethodSetId = "Method_Set_Id", StartTime = DateTime.Now - TimeSpan.FromMinutes(7), FinishTime = DateTime.Now, InspectionPlace = InspectionPlace.OnWorkplace, InspectionType = InspectionType.PreShift, EmployeeId = Guid.NewGuid().ToString(), BranchOfficeId = Guid.NewGuid().ToString(), DepartmentId = Guid.NewGuid().ToString(), MachineName = "HOST002", MethodSetVersion = "Version 16" }; // When var response = controller.PostInspection(newInspectionModel); // Then _inspectionService.Received().BeginInspectionAsync(Arg.Any <Inspection>()); _inspectionService.Received().BeginInspectionAsync( Arg.Is <Inspection>(v => v.StartTime == newInspectionModel.StartTime && v.TenantId == _tenantId)); var createdResponse = (CreatedResult)response.Result; Assert.That(createdResponse.Location, Is.EqualTo(nameof(InspectionController.GetInspection))); var createdAttribs = (CreatedWithGuidDto)createdResponse.Value; Assert.That(createdAttribs.Id, Is.EqualTo(_newId)); }
public async Task SubmitInspection_ShouldSucceed_GivenOperatorWorkplace() { // Given // client authenticated as operator workplace await _apiClient.SignInWithWorkplaceCredentialsAsync( _operatorWorkplaceCredentials.ClientId, _operatorWorkplaceCredentials.ClientSecret, PskOnlineScopes.DeptOperatorWorkplace); var workplaceIdToken = _apiClient.GetIdToken(); var departmentId = workplaceIdToken.Claims.First(c => c.Type == CustomClaimTypes.DepartmentId).Value; var employees = await _apiClient.GetDepartmentEmployeesAsync(departmentId); var employee = employees.First(); // When // the department operator workplace submits inspection & test data for an employee in the department var inspectionDto = new InspectionDto { MethodSetId = "Method_Set_Id", StartTime = DateTime.Now - TimeSpan.FromMinutes(7), InspectionPlace = InspectionPlace.OnWorkplace, InspectionType = InspectionType.PreShift, EmployeeId = employee.Id, MachineName = "HOST002", MethodSetVersion = "Version 16" }; var inspectionId = await _apiClient.PostInspectionAsync(inspectionDto); // Then // the request should succeed var verifyInspection = await _apiClient.GetInspectionAsync(inspectionId); // And the attempt to post a test for the inspectioin should succeed var testDto = new TestDto { Id = Guid.NewGuid().ToString(), MethodId = "123", MethodVersion = "1.0", InspectionId = inspectionId.ToString(), EmployeeId = inspectionDto.EmployeeId, StartTime = inspectionDto.StartTime, FinishTime = inspectionDto.StartTime + TimeSpan.FromMinutes(5), MethodProcessedDataJson = JObject.Parse("{}"), MethodRawDataJson = JObject.Parse("{ \"value\" : \"Qw2er6ty1as6df36k347j3q2w2er8o9iu2234wer\"}") }; var testId = await _apiClient.PostTestAsync(testDto); // And the attempt to complete the inspection should succeed var responseDto = await _apiClient.CompleteInspectionAsync(new InspectionCompleteDto { Id = inspectionId, FinishTime = inspectionDto.StartTime + TimeSpan.FromMinutes(5) }); Assert.NotNull(responseDto); // and the Tenant Operations Statistics should return +1 completed inspection await _apiClient.AsGryffindorAdminAsync(_httpClient); var tenantId = workplaceIdToken.GetTenantIdClaimValue(); var opsStat = await _apiClient.GetTenantOperationsSummaryAsync(tenantId); Assert.That(opsStat.NewInspectionsLast24Hours, Is.EqualTo(1)); Assert.That(opsStat.NewInspectionsLastWeek, Is.EqualTo(1)); }
public InspectionDto CreateInspection(InspectionDto input) { throw new NotImplementedException(); }
public string UpdateMission(BillInfoDto input) { bool canAssignInspectionToOther = PermissionChecker.IsGranted(PermissionNames.Pages_Inspection); //如果任务已经分配且未分配给自己,且不具有分配任务权限,则抛出异常 if (!canAssignInspectionToOther) { #region 修改信息处理 input.Id = Snowflake.Instance().GetId(); //分布式ID作为主键 var result = Mapper.Map <BillInfo>(input); result.UpVersion(); //版本号加一 result.ChangeIsCandidate(); //设为候选待审核 _BillInfoRepository.Insert(result); #endregion #region 检查是否有同货票号且正在生效中信息 var task = _BillInfoRepository.GetAll() .Where(t => t.BillNo == input.BillNo && t.IsCandidate == false); #endregion // if (input.State == 1)//审核时提出修改信息,新增同货票号新信息,未审核通过时 IsCandidate 状态为1(未审核),同时生成对应审核表内容 if (task.ToList().Count <= 0) { return("该货票基本信息已被删除,不能提出修改"); } //原基本信息不存在,不能修改 else { var taskss = task.Where(t => t.BillStateID == 2).ToList();//订单状态为已签收 if (taskss.Count > 0) { #region 审核信息新建 InspectionDto inspectionDto = new InspectionDto { Id = null, Inspection_No = Snowflake.Instance().GetId(), SourceType = "货票", SourceNo = task.FirstOrDefault().Id, StartDate = DateTime.UtcNow, DestinationNO = result.Id, Version = 1, ProposerName = "", ProposerID = AbpSession.GetUserId(), Title = "货票 修改", IsCandidate = true, InspectionState = 0, InspectionName = null, Action = "修改", InspectionMemo = "", EndDate = null, Quality_level = 1 }; var inspection = Mapper.Map <Inspection>(inspectionDto); _Inspectionrepository.Insert(inspection); #endregion } else { #region 非已签收状态直接修改 try { var task_t = _BillInfoRepository.GetAll().Where(t => t.Id == input.Id && t.IsCandidate == false); var result_t = Mapper.Map <BillInfo>(input); result_t.UpVersion(); //版本号加一 if (task_t != null) { _BillInfoRepository.Update(result_t); return("修改成功"); } else { return("修改失败"); } } catch { return("修改失败"); } #endregion } return("提出修改成功"); } //throw new AbpAuthorizationException("没有分配任务给他人的权限!"); } else { #region 管理员直接修改 try { var task = _BillInfoRepository.GetAll().Where(t => t.Id == input.Id && t.IsCandidate == false); var result = Mapper.Map <BillInfo>(input); result.UpVersion(); //版本号加一 if (task != null) { _BillInfoRepository.Update(result); return("修改成功"); } else { return("修改失败"); } } catch { return("修改失败"); } #endregion } }