public void TestVehicleInspections() { List <VehicleInspection> vehicleInspections = AppDb.GetVehicleInspections().ToList(); if (vehicleInspections.Any()) { VehicleInspection first = vehicleInspections.First(); VehicleInspection response = AppDb.GetVehicleInspection(first.Id); } }
protected void btnAddInspection_Click(object sender, EventArgs e) { // Parse the dates int ID = Parsers.ParseInt(txtVehicleID.Value); string description = txtNewInspectionDescription.Text; DateTime inspectionEffectiveDate = DateTime.ParseExact(txtEffectiveDate.Text, "yyyy-MM-dd", CultureInfo.InvariantCulture); DateTime inspectionExpires = DateTime.ParseExact(txtExpiryDate.Text, "yyyy-MM-dd", CultureInfo.InvariantCulture); VehicleInspectionRepository vir = new VehicleInspectionRepository(); VehicleInspection i = vir.Add(ID, description, inspectionEffectiveDate, inspectionExpires); if (i != null) { tblInspections.Rows.Add(addRow(i)); } }
public IActionResult Put([FromBody] VehicleInspection vehicleInspection) { try { if (ModelState.IsValid && _unitOfWork.VehicleInspection.Update(vehicleInspection)) { return(Ok(new { Message = "Solicitud de inspección del vehículo actualizados" })); } else { return(BadRequest()); } } catch (Exception ex) { return(StatusCode(500, "Internal server error: " + ex.Message)); } }
TableRow addRow(VehicleInspection i) { TableRow row = new TableRow(); row.Cells.Add(new TableCell() { Text = i.Description }); row.Cells.Add(new TableCell() { Text = i.EffectiveDate.ToLongDateString() }); row.Cells.Add(new TableCell() { Text = i.ExpiryDate.ToLongDateString() }); return(row); }
/// <summary> /// Adds the yanche information. /// </summary> /// <param name="caseId">The case identifier.</param> /// <param name="yancheInfo">The yanche information.</param> /// <param name="photos">The photos.</param> /// <returns>Task<Case>.</returns> /// <exception cref="ApplicationException"> /// 事项的状态不合法 /// or /// 未能加载验车信息 /// or /// 无法加载用户信息 /// or /// 无在岗查询师 /// or /// 查询师分配错误 /// </exception> /// <exception cref="System.ApplicationException"> /// 事项的状态不合法 /// or /// 未能加载验车信息 /// </exception> public async Task<Case> AddYancheInfoAsync(int caseId, VehicleInspection yancheInfo, IEnumerable<int> photos) { using (ChePingContext db = new ChePingContext()) { Case @case = await db.Cases.FirstOrDefaultAsync(c => c.Id == caseId); if (@case == null || @case.State != State.Yanche) { throw new ApplicationException("事项的状态不合法"); } VehicleInspection inspection = await db.VehicleInspections.FirstOrDefaultAsync(i => i.Id == @case.VehicleInspecId); if (inspection == null) { throw new ApplicationException("未能加载验车信息"); } inspection.VinCode = yancheInfo.VinCode; inspection.EngineCode = yancheInfo.EngineCode; inspection.InsuranceCode = yancheInfo.InsuranceCode; inspection.LicenseCode = yancheInfo.LicenseCode; @case.State = State.Chaxun; this.RecordTime(@case, State.Yanche); User user = await db.Users.FirstOrDefaultAsync(u => u.Id == @case.PurchaserId && u.JobTitle == JobTitle.Purchaser && u.Available); if (user == null) { throw new ApplicationException("无法加载用户信息"); } int queryingId; List<User> queryings = await db.Users.Where(u => u.Available && u.JobTitle == JobTitle.Querying).ToListAsync(); var workingQueryings = await db.Cases.Where(c => QueryingTodoStates.Contains(c.State) && c.QueryingId != null) .GroupBy(c => c.QueryingId).Select(g => new { g.Key, Count = g.Count() }).ToListAsync(); queryings.RemoveAll(v => workingQueryings.Select(i => i.Key).Contains(v.Id)); if (queryings.Count > 0) { queryingId = queryings[0].Id; } else { if (workingQueryings.Count == 0) { throw new ApplicationException("无在岗查询师"); } queryingId = workingQueryings.OrderBy(v => v.Count).Select(v => v.Key).First().GetValueOrDefault(); if (queryingId == 0) { throw new ApplicationException("查询师分配错误"); } } @case.QueryingId = queryingId; foreach (int photo in photos) { Photo photoModel = await db.Photos.FirstOrDefaultAsync(p => p.Id == photo); if (photoModel != null) { photoModel.CaseId = caseId; } } await db.ExecuteSaveChangesAsync(); await this.smsService.SendNoticeMessage(@case.QueryingId.GetValueOrDefault()); return @case; } }
/// <summary> /// add value information as an asynchronous operation. /// </summary> /// <param name="caseId">The case identifier.</param> /// <param name="valueInfo">The value information.</param> /// <param name="price">The price.</param> /// <returns>Task<Case>.</returns> /// <exception cref="ApplicationException"> /// 事项的状态不合法 /// or /// 未能加载验车信息 /// </exception> /// <exception cref="System.ApplicationException"> /// 事项的状态不合法 /// or /// 未能加载验车信息 /// </exception> public async Task<Case> AddValueInfoAsync(int caseId, VehicleInspection valueInfo, int price) { using (ChePingContext db = new ChePingContext()) { Case @case = await db.Cases.FirstOrDefaultAsync(c => c.Id == caseId); if (@case == null || @case.State != State.Pinggu) { throw new ApplicationException("事项的状态不合法"); } VehicleInspection inspection = await db.VehicleInspections.FirstOrDefaultAsync(i => i.Id == @case.VehicleInspecId); if (inspection == null) { throw new ApplicationException("未能加载验车信息"); } inspection.PreferentialPrice = valueInfo.PreferentialPrice; inspection.MaxMileage = valueInfo.MaxMileage; inspection.MinMileage = valueInfo.MinMileage; inspection.SaleGrade = valueInfo.SaleGrade; inspection.WebAveragePrice = valueInfo.WebAveragePrice; inspection.WebPrice = valueInfo.WebPrice; inspection.FloorPrice = valueInfo.FloorPrice; this.RecordTime(@case, State.Pinggu); //alloc directorId User user = await db.Users.FirstOrDefaultAsync(u => u.Id == @case.PurchaserId && u.JobTitle == JobTitle.Purchaser && u.Available); if (user == null) { throw new ApplicationException("无法加载用户信息"); } List<User> directors = await db.Users.Where(u => u.Available && u.OutletId == user.OutletId && u.JobTitle == JobTitle.Director).ToListAsync(); if (directors.Count == 0) { throw new ApplicationException("无在岗地区总监"); } int caseCount = await db.Cases.CountAsync(c => c.OutletId == user.OutletId && DirectorTodoStates.Contains(c.State) && c.DirectorId != null); int index = caseCount % directors.Count; int directorId = directors[index].Id; @case.State = State.Shenhe; @case.PurchasePrice = price; @case.DirectorId = directorId; await db.ExecuteSaveChangesAsync(); return @case; } }
/// <summary> /// add qiatan information as an asynchronous operation. /// </summary> /// <param name="caseId">The case identifier.</param> /// <param name="qiatanInfo">The qiatan information.</param> /// <returns>Task<Case>.</returns> /// <exception cref="ApplicationException"> /// 事项的状态不合法 /// or /// 未能加载验车信息 /// </exception> public async Task<Case> AddQiatanInfoAsync(int caseId, VehicleInspection qiatanInfo) { using (ChePingContext db = new ChePingContext()) { Case @case = await db.Cases.FirstOrDefaultAsync(c => c.Id == caseId); if (@case == null || @case.State != State.Qiatan) { throw new ApplicationException("事项的状态不合法"); } VehicleInspection inspection = await db.VehicleInspections.FirstOrDefaultAsync(i => i.Id == @case.VehicleInspecId); if (inspection == null) { throw new ApplicationException("未能加载验车信息"); } inspection.VehicleOwner = qiatanInfo.VehicleOwner; inspection.VehicleOwnerCellphone = qiatanInfo.VehicleOwnerCellphone; inspection.VehicleOwnerBank = qiatanInfo.VehicleOwnerBank; inspection.VehicleOwnerBankCardNo = qiatanInfo.VehicleOwnerBankCardNo; inspection.VehicleOwnerIdNo = qiatanInfo.VehicleOwnerIdNo; @case.State = State.ShenqingDakuan; this.RecordTime(@case, State.Qiatan); await db.ExecuteSaveChangesAsync(); await this.smsService.SendNoticeMessage(@case.DirectorId.GetValueOrDefault()); return @case; } }
/// <summary> /// add chaxun information as an asynchronous operation. /// </summary> /// <param name="caseId">The case identifier.</param> /// <param name="chaxunInfo">The chaxun information.</param> /// <returns>Task<Case>.</returns> /// <exception cref="System.ApplicationException"> /// 事项的状态不合法 /// or /// 未能加载验车信息 /// </exception> public async Task<Case> AddChaxunInfoAsync(int caseId, VehicleInspection chaxunInfo) { using (ChePingContext db = new ChePingContext()) { Case @case = await db.Cases.FirstOrDefaultAsync(c => c.Id == caseId); if (@case == null || @case.State != State.Chaxun) { throw new ApplicationException("事项的状态不合法"); } VehicleInspection inspection = await db.VehicleInspections.FirstOrDefaultAsync(i => i.Id == @case.VehicleInspecId); if (inspection == null) { throw new ApplicationException("未能加载验车信息"); } inspection.RealMileage = chaxunInfo.RealMileage; inspection.LastConservationTime = chaxunInfo.LastConservationTime; inspection.ConservationState = chaxunInfo.ConservationState; inspection.ConservationNote = chaxunInfo.ConservationNote; inspection.ClaimState = chaxunInfo.ClaimState; inspection.ClaimNote = chaxunInfo.ClaimNote; inspection.BondsState = chaxunInfo.BondsState; inspection.BondsNote = chaxunInfo.BondsNote; inspection.ViolationState = chaxunInfo.ViolationState; inspection.ViolationNote = chaxunInfo.ViolationNote; @case.State = State.Baojia; this.RecordTime(@case, State.Chaxun); await db.ExecuteSaveChangesAsync(); return @case; } }
/// <summary> /// add special case as an asynchronous operation. /// </summary> /// <param name="case">The case.</param> /// <param name="info">The information.</param> /// <param name="photos">The photos.</param> /// <returns>Task<CaseDto>.</returns> /// <exception cref="ApplicationException">无法加载用户信息</exception> /// <exception cref="System.ApplicationException">无法加载用户信息</exception> private async Task<Case> AddSpecialCaseAsync(Case @case, VehicleInfo info, IEnumerable<int> photos) { Case newCase = new Case { Abandon = false, AbandonReason = "", CaseType = @case.CaseType, DirectorId = null, // need update ManagerId = null, OutletId = 0, // need update PurchasePrice = 0, PurchaserId = @case.PurchaserId, QueryingId = null, SerialId = @case.SerialId, State = State.Shenhe, ValuerId = null, VehicleInfoId = 0, // need update VehicleInspecId = 0, // need update CreateTime = DateTime.UtcNow.AddHours(8) }; VehicleInfo newInfo = new VehicleInfo { BrandName = info.BrandName, CooperationMethod = info.CooperationMethod, DisplayMileage = info.DisplayMileage, ExpectedPrice = info.ExpectedPrice, FactoryTime = info.FactoryTime, InnerColor = info.InnerColor, InnerColorName = info.InnerColorName, LicenseLocation = info.LicenseLocation, LicenseTime = info.LicenseTime, ModelId = info.ModelId, ModelName = info.ModelName, ModifiedContent = info.ModifiedContent, OuterColor = info.OuterColor, OuterColorName = info.OuterColorName, SeriesName = info.SeriesName, VehicleLocation = info.VehicleLocation }; VehicleInspection newVehicleInspection = new VehicleInspection(); int purchaserId = @case.PurchaserId; using (ChePingContext db = new ChePingContext()) { await db.SaveAsync(newInfo); await db.SaveAsync(newVehicleInspection); User user = await db.Users.FirstOrDefaultAsync(u => u.Id == purchaserId && u.JobTitle == JobTitle.Purchaser && u.Available); if (user == null) { throw new ApplicationException("无法加载用户信息"); } List<User> directors = await db.Users.Where(u => u.Available && u.OutletId == user.OutletId && u.JobTitle == JobTitle.Director).ToListAsync(); int caseCount = await db.Cases.CountAsync(c => c.OutletId == user.OutletId && DirectorTodoStates.Contains(c.State) && c.DirectorId != null); int index = caseCount % directors.Count; int directorId = directors[index].Id; newCase.DirectorId = directorId; newCase.OutletId = user.OutletId; newCase.VehicleInfoId = newInfo.Id; newCase.VehicleInspecId = newVehicleInspection.Id; await db.SaveAsync(newCase); foreach (int photo in photos) { Photo photoModel = await db.Photos.FirstOrDefaultAsync(p => p.Id == photo); if (photoModel != null) { photoModel.CaseId = newCase.Id; } } await db.ExecuteSaveChangesAsync(); } return newCase; }
/// <summary> /// add general case as an asynchronous operation. /// </summary> /// <param name="case">The case.</param> /// <param name="info">The information.</param> /// <param name="photos">The photos.</param> /// <returns>System.Threading.Tasks.Task<ChepingServer.Models.Case>.</returns> /// <exception cref="ApplicationException"> /// 无法加载用户信息 /// or /// 无在岗评估师,事项添加失败 /// or /// 评估师分配错误,事项添加失败 /// </exception> /// <exception cref="System.ApplicationException"> /// 无法加载车型信息 /// or /// 无法加载用户信息 /// or /// 无在岗评估师,事项添加失败 /// or /// 评估师分配错误,事项添加失败 /// </exception> private async Task<Case> AddGeneralCaseAsync(Case @case, VehicleInfo info, IEnumerable<int> photos) { Case newCase = new Case { Abandon = false, AbandonReason = "", CaseType = @case.CaseType, DirectorId = null, ManagerId = null, OutletId = 0, // need update PurchasePrice = 0, PurchaserId = @case.PurchaserId, QueryingId = null, SerialId = @case.SerialId, State = State.Pinggu, ValuerId = null, // need update VehicleInfoId = 0, // need update VehicleInspecId = 0, // need update CreateTime = DateTime.UtcNow.AddHours(8), Times = null }; VehicleInfo newInfo = new VehicleInfo { BrandName = info.BrandName, CooperationMethod = info.CooperationMethod, DisplayMileage = info.DisplayMileage, ExpectedPrice = info.ExpectedPrice, FactoryTime = info.FactoryTime, InnerColor = info.InnerColor, InnerColorName = info.InnerColorName, LicenseLocation = info.LicenseLocation, LicenseTime = info.LicenseTime, ModelId = info.ModelId, ModelName = info.ModelName, ModifiedContent = info.ModifiedContent, OuterColor = info.OuterColor, OuterColorName = info.OuterColorName, SeriesName = info.SeriesName, VehicleLocation = info.VehicleLocation }; VehicleInspection newVehicleInspection = new VehicleInspection(); int purchaserId = @case.PurchaserId; using (ChePingContext db = new ChePingContext()) { await db.SaveAsync(newInfo); await db.SaveAsync(newVehicleInspection); User user = await db.Users.FirstOrDefaultAsync(u => u.Id == purchaserId && u.JobTitle == JobTitle.Purchaser && u.Available); if (user == null) { throw new ApplicationException("无法加载用户信息"); } int valuerId; List<User> valuers = await db.Users.Where(u => u.Available && !u.HangOn && u.JobTitle == JobTitle.Valuer && u.ValuerGroup.Contains(((int)newCase.CaseType).ToString())).ToListAsync(); var workingValuers = await db.Cases.Where(c => ValuerTodoStates.Contains(c.State) && c.ValuerId != null) .GroupBy(c => c.ValuerId).Select(g => new { g.Key, Count = g.Count() }).ToListAsync(); valuers.RemoveAll(v => workingValuers.Select(i => i.Key).Contains(v.Id)); if (valuers.Count > 0) { valuerId = valuers[0].Id; } else { if (workingValuers.Count == 0) { throw new ApplicationException("无在岗评估师,事项添加失败"); } valuerId = workingValuers.OrderBy(v => v.Count).Select(v => v.Key).First().GetValueOrDefault(); if (valuerId == 0) { throw new ApplicationException("评估师分配错误,事项添加失败"); } } newCase.ValuerId = valuerId; newCase.OutletId = user.OutletId; newCase.VehicleInfoId = newInfo.Id; newCase.VehicleInspecId = newVehicleInspection.Id; await db.SaveAsync(newCase); foreach (int photo in photos) { Photo photoModel = await db.Photos.FirstOrDefaultAsync(p => p.Id == photo); if (photoModel != null) { photoModel.CaseId = newCase.Id; } } await db.ExecuteSaveChangesAsync(); await this.smsService.SendNoticeMessage(newCase.ValuerId.GetValueOrDefault()); } return newCase; }
public async Task<IHttpActionResult> AddYancheInfo(AddYancheInfoRequest request) { Case @case = await this.caseService.GetAsync(request.CaseId); if (@case == null) { return this.BadRequest("无法加载事项信息"); } if (@case.PurchaserId != this.CurrentUser.Id) { return this.BadRequest("操作未授权"); } if (@case.State != State.Yanche) { return this.BadRequest("事项状态错误"); } VehicleInspection inspection = new VehicleInspection { VinCode = request.VinCode, EngineCode = request.EngineCode, InsuranceCode = request.InsuranceCode, LicenseCode = request.LicenseCode }; @case = await this.caseService.AddYancheInfoAsync(@case.Id, inspection, request.PhotoIds); return this.Ok(@case.ToDto()); }
public async Task<IHttpActionResult> AddValueInfo(AddValueInfoRequest request) { Case @case = await this.caseService.GetAsync(request.CaseId); if (@case == null) { return this.BadRequest("无法加载事项信息"); } if (@case.ValuerId.GetValueOrDefault(-100) != this.CurrentUser.Id) { return this.BadRequest("操作未授权"); } if (@case.State != State.Pinggu) { return this.BadRequest("事项状态错误"); } VehicleInspection inspection = new VehicleInspection { PreferentialPrice = request.PreferentialPrice, MaxMileage = request.MaxMileage, MinMileage = request.MinMileage, SaleGrade = request.SaleGrade, WebAveragePrice = request.WebAveragePrice, WebPrice = request.WebPrice, FloorPrice = request.FloorPrice }; @case = await this.caseService.AddValueInfoAsync(@case.Id, inspection, request.Price); return this.Ok(@case.ToDto()); }
public async Task<IHttpActionResult> AddQiatanInfo(AddQiatanInfoRequest request) { Case @case = await this.caseService.GetAsync(request.CaseId); if (@case == null) { return this.BadRequest("无法加载事项信息"); } if (@case.PurchaserId != this.CurrentUser.Id) { return this.BadRequest("操作未授权"); } if (@case.State != State.Qiatan) { return this.BadRequest("事项状态错误"); } VehicleInspection inspection = new VehicleInspection { VehicleOwner = request.VehicleOwner, VehicleOwnerCellphone = request.VehicleOwnerCellphone, VehicleOwnerBank = request.VehicleOwnerBank, VehicleOwnerBankCardNo = request.VehicleOwnerBankCardNo, VehicleOwnerIdNo = request.VehicleOwnerIdNo }; @case = await this.caseService.AddQiatanInfoAsync(@case.Id, inspection); return this.Ok(@case.ToDto()); }
public async Task<IHttpActionResult> AddChaxunInfo(AddChaxunInfoRequest request) { Case @case = await this.caseService.GetAsync(request.CaseId); if (@case == null) { return this.BadRequest("无法加载事项信息"); } if (@case.QueryingId.GetValueOrDefault(-100) != this.CurrentUser.Id) { return this.BadRequest("操作未授权"); } if (@case.State != State.Chaxun) { return this.BadRequest("事项状态错误"); } VehicleInspection inspection = new VehicleInspection { RealMileage = request.RealMileage, LastConservationTime = request.LastConservationTime, ConservationState = request.ConservationState, ConservationNote = request.ConservationNote, ClaimState = request.ClaimState, ClaimNote = request.ClaimNote, BondsState = request.BondsState, BondsNote = request.BondsNote, ViolationState = request.ViolationState, ViolationNote = request.ViolationNote }; @case = await this.caseService.AddChaxunInfoAsync(@case.Id, inspection); return this.Ok(@case.ToDto()); }
public VehicleInspection SaveInspection(VehicleInspection inspection, int userId, List <int> checkedList, bool apiCall = false) { if (inspection.Id > 0) { var m = _currentDbContext.VehicleInspections.First(x => x.Id == inspection.Id); m.DriverSignature = inspection.DriverSignature; m.FleetNumber = inspection.FleetNumber; if (apiCall == true) { m.VehicleDriverId = _userService.GetResourceIdByUserId(inspection.VehicleDriverId); } m.MileageReading = inspection.MileageReading; m.NilDefect = inspection.NilDefect; m.RectifiedUserId = inspection.RectifiedUserId; m.RectifiedDateTime = inspection.RectifiedDateTime; m.ReportedToUserId = inspection.ReportedToUserId; m.Notes = inspection.Notes; m.UpdateUpdatedInfo(userId); m.CreatedBy = m.CreatedBy; m.DateCreated = m.DateCreated; var deletedList = m.ConfirmedChecklists.Where(s => !checkedList.Contains(s.VehicleInspectionCheckListId)).ToList(); foreach (var item in deletedList) { _currentDbContext.Entry(item).State = EntityState.Deleted; } _currentDbContext.SaveChanges(); var newItems = checkedList.Where(c => !m.ConfirmedChecklists.Select(s => s.VehicleInspectionCheckListId).Contains(c)); foreach (var item in newItems) { _currentDbContext.VehicleInspectionConfirmedLists.Add(new VehicleInspectionConfirmedList() { VehicleInspectionCheckListId = item, VehicleInspection = m }); } _currentDbContext.SaveChanges(); } else { inspection.InspectionDateTime = DateTime.UtcNow; inspection.UpdateCreatedInfo(userId); if (apiCall == true) { inspection.VehicleDriverId = _userService.GetResourceIdByUserId(inspection.VehicleDriverId); } foreach (var item in checkedList) { inspection.ConfirmedChecklists.Add(new VehicleInspectionConfirmedList() { VehicleInspectionCheckListId = item, VehicleInspection = inspection }); } _currentDbContext.Entry(inspection).State = EntityState.Added; _currentDbContext.SaveChanges(); } return(inspection); }