public void UpdateWork(Objects.Work work) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Work> repository = new Repositor <Work>(unitOfWork); try { ObjectValidator.IsValid(work); unitOfWork.BeginTransaction(); var w = repository.Single(c => c.WorkID == work.ID); if (w.Date.DateIsClosed) { throw new DateException("Směna je uzamčená, nelze odebírat ani editovat záznamy"); } w.WorkVehicleID = work.VehicleID; w.WorkWorkTypeID = work.WorkTypeID; w.WorkFaultDescription = String.IsNullOrWhiteSpace(work.FaultDescription) ? null : work.FaultDescription; w.WorkCauseDescription = String.IsNullOrWhiteSpace(work.CauseDescription) ? null : work.CauseDescription; repository.Update(w); unitOfWork.CommitTransaction(); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public Int64 AddWork(Objects.Work work) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Work> repository = new Repositor <Work>(unitOfWork); try { ObjectValidator.IsValid(work); Work w = new Work(); w.WorkDateID = work.DateID; w.WorkVehicleID = work.VehicleID; w.WorkWorkTypeID = work.WorkTypeID; w.WorkFaultDescription = String.IsNullOrWhiteSpace(work.FaultDescription) ? null : work.FaultDescription; w.WorkCauseDescription = String.IsNullOrWhiteSpace(work.CauseDescription) ? null : work.CauseDescription; unitOfWork.BeginTransaction(); repository.Add(w); unitOfWork.CommitTransaction(); return(w.WorkID); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }