public void Delete(Guid id) { _unitOfWork.BeginTransaction(); var mechanic = _mechanicRepository.GetById(id); if (mechanic == null) { _unitOfWork.Commit(); throw new Exception(ExceptionMessages.MechanicException.NOT_FOUND); } _mechanicRepository.Delete(mechanic); _unitOfWork.Commit(); }
public Guid Create(CreateTechnicalInspectionViewModel model) { _unitOfWork.BeginTransaction(); var mechanic = _mechanicRepository.GetById(model.Mechanic.Id); if (mechanic == null) { _unitOfWork.Commit(); throw new Exception(ExceptionMessages.MechanicException.NOT_FOUND); } var vehicle = _vehicleRepository.GetById(model.Vehicle.Id); if (vehicle == null) { _unitOfWork.Commit(); throw new Exception(ExceptionMessages.VehicleException.NOT_FOUND); } var user = _userRepository.GetById(model.User.Id); if (user == null) { _unitOfWork.Commit(); throw new Exception(ExceptionMessages.UserException.NOT_FOUND); } var inspection = new TechnicalInspection(mechanic, vehicle, user, model.UserNote); _technicalInspectionRepository.Add(inspection); _unitOfWork.Commit(); return(inspection.Id); }
public void UpdateMechanic(MechanicViewModel mechanic, int userId) { Mechanic entity = _mechanicRepository.GetById(mechanic.Id); Map(mechanic, entity); entity.ModifyDate = DateTime.Now; entity.ModifyUserId = userId; _mechanicRepository.Update(entity); _unitOfWork.SaveChanges(); }
public void DeleteMechanic(MechanicViewModel mechanic, int userId) { Mechanic entity = _mechanicRepository.GetById(mechanic.Id); entity.Status = (int)DbConstant.DefaultDataStatus.Deleted; entity.ModifyDate = DateTime.Now; entity.ModifyUserId = userId; _mechanicRepository.Update(entity); _unitOfWork.SaveChanges(); }
public List <MechanicViewModel> GetInvolvedMechanic(int SPKId) { List <SPKSchedule> allMechanicInSPK = _SPKScheduleRepository.GetMany( sc => sc.SPKId == SPKId && sc.Status == (int)DbConstant.DefaultDataStatus.Active).ToList(); List <Mechanic> result = new List <Mechanic>(); foreach (int mechanicID in allMechanicInSPK.Select(m => m.MechanicId).Distinct()) { result.Add(_mechanicRepository.GetById(mechanicID)); } List <MechanicViewModel> mappedResult = new List <MechanicViewModel>(); Map(result, mappedResult); return(mappedResult); }