public ActionResult CloseTicket(VehicleRepair repair, IEnumerable <HttpPostedFileBase> image) { if (ModelState.IsValid) { foreach (var item in image) { string error; if (!FileHelper.CheckIfFileIsImage(item, out error)) { ModelState.AddModelError("", error); return(View(repair)); } } string basePath = Server.MapPath(Constants.VEHICLE_REPAIR_UPLOAD_BASE_PATH + repair.Id + "/"); FileHelper.SaveFiles(image, basePath); VehicleDamageStatus status = db.VehicleDamagesStatus.Find(TempData.Peek("StatusId")); repair.Id = status.VehicleDamageId; db.VehicleRepairs.Add(repair); db.SaveChanges(); status.Action = DamageAction.Closed; db.Entry(status).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("ViewClosedTickets")); } return(View(repair)); }
/// <summary> /// Method to add vehicle repair - SS /// </summary> /// <param name="addVehicleRepair">vehicle repair</param> /// <param name="loggedInUser">logged in user</param> /// <returns>response</returns> public async Task <VehicleRepairManagementResponse> AddVehicleRepairAsync(AddVehicleRepairManagementAc addVehicleRepair, ApplicationUser loggedInUser) { if (string.IsNullOrEmpty(addVehicleRepair.Code.Trim())) { return new VehicleRepairManagementResponse() { HasError = true, Message = "Code can't be empty", ErrorType = VehicleRepairManagementResponseType.Code } } ; else { var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true); if (!await _iMSDbContext.VehicleMasters.AnyAsync(x => x.Id == addVehicleRepair.VehicleId && x.InstituteId == instituteId)) { return new VehicleRepairManagementResponse() { HasError = true, Message = "Vehicle not found", ErrorType = VehicleRepairManagementResponseType.VehicleId } } ; else { if (await _iMSDbContext.VehicleRepairs.AnyAsync(x => x.Code.ToLowerInvariant() == addVehicleRepair.Code.ToLowerInvariant() && x.Vehicle.InstituteId == instituteId)) { return new VehicleRepairManagementResponse() { HasError = true, Message = "Vehicle repair code already exist, Please use unique one", ErrorType = VehicleRepairManagementResponseType.Code } } ; else { var repair = new VehicleRepair() { Code = addVehicleRepair.Code, CreatedOn = DateTime.UtcNow, Remarks = addVehicleRepair.Remarks, RepairCost = addVehicleRepair.RepairCost, RepairDate = addVehicleRepair.RepairDate, UpdatedById = loggedInUser.Id, UpdatedOn = DateTime.UtcNow, VehicleId = addVehicleRepair.VehicleId }; _iMSDbContext.VehicleRepairs.Add(repair); await _iMSDbContext.SaveChangesAsync(); return(new VehicleRepairManagementResponse() { HasError = false, Message = "Vehicle repair added successfully" }); } } } }
public void TestVehicleRepairs() { List <VehicleRepair> vehicleRepairs = AppDb.GetVehicleRepairs().ToList(); if (vehicleRepairs.Any()) { VehicleRepair first = vehicleRepairs.First(); VehicleRepair response = AppDb.GetVehicleRepair(first.Id); } }
public ActionResult CloseTicket(Guid id) { TempData["StatusId"] = id; VehicleDamageStatus status = db.VehicleDamagesStatus.Find(id); VehicleRepair reapir = new VehicleRepair { Id = status.VehicleDamageId, VehicleDamage = status.VehicleDamage }; return(View(reapir)); }