public void UpdateAttendance(Objects.Attendance attendance) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Attendance> repository = new Repositor <Attendance>(unitOfWork); try { ObjectValidator.IsValid(attendance); unitOfWork.BeginTransaction(); var a = repository.Single(c => c.AttendanceDateID == attendance.DateID && c.AttendanceWorkerID == attendance.WorkerID); if (a.Date.DateIsClosed) { throw new DateException("Směna je uzamčená, nelze odebírat ani editovat záznamy"); } a.AttendanceWorkerStateID = attendance.WorkerStateID; a.AttendanceWorkerTourID = attendance.WorkerTourID; a.AttendanceDescription = String.IsNullOrWhiteSpace(attendance.Description) ? null : attendance.Description; repository.Update(a); unitOfWork.CommitTransaction(); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
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 Objects.User GetUserInfo(string userName) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <User> repository = new Repositor <User>(unitOfWork); try { var u = repository.Single(c => c.UserName == userName); var user = new Objects.User(); user.ID = u.UserID; user.Name = u.UserName; user.WorkerID = u.UserWorkerID; user.Description = u.UserDescription; user.DetachmentID = u.UserDetachmentID; user.Roles = u.Roles.Select(c => new Objects.Role() { ID = c.RoleID, Name = c.RoleName }); return(user); } catch (Exception e) { throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public Objects.WorkerDetail FindWorker(Int32 workerID) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Worker> repository = new Repositor <Worker>(unitOfWork); try { var w = repository.Single(c => c.WorkerID == workerID); Objects.WorkerDetail worker = new Objects.WorkerDetail(); worker.ID = w.WorkerID; worker.FirstName = w.WorkerFirstName; worker.LastName = w.WorkerLastName; worker.ServiceNumber = w.WorkerServiceNumber; worker.SapNumber = w.WorkerSapNumber; worker.ServiceEmail = w.WorkerServiceEmail; worker.PersonalEmail = w.WorkerPersonalEmail; worker.ServicePhone = w.WorkerServicePhone; worker.PersonalPhone = w.WorkerPersonalPhone; worker.Description = w.WorkerDescription; worker.Photo = w.WorkerPhoto; worker.DetachmentID = w.WorkerDetachmentID; worker.Tours = w.Tours.Select(c => new Objects.Tour() { ID = c.TourID, Description = c.TourDescription, EndTime = c.TourEndTime, StartTime = c.TourStartTime }); return(worker); } catch (Exception e) { throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public void UpdateWorker(Objects.WorkerDetail worker) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Worker> repository = new Repositor <Worker>(unitOfWork); IRepository <Tour> repositoryTour = new Repositor <Tour>(unitOfWork); try { ObjectValidator.IsValid(worker); unitOfWork.BeginTransaction(); var w = repository.Single(c => c.WorkerID == worker.ID); w.WorkerServiceEmail = String.IsNullOrWhiteSpace(worker.ServiceEmail) ? null : worker.ServiceEmail; w.WorkerPersonalEmail = String.IsNullOrWhiteSpace(worker.PersonalEmail) ? null : worker.PersonalEmail; w.WorkerServicePhone = String.IsNullOrWhiteSpace(worker.ServicePhone) ? null : worker.ServicePhone; w.WorkerPersonalPhone = String.IsNullOrWhiteSpace(worker.PersonalPhone) ? null : worker.PersonalPhone; w.WorkerDescription = String.IsNullOrWhiteSpace(worker.Description) ? null : worker.Description; w.WorkerPhoto = worker.Photo; var oldIds = w.Tours.Select(c => c.TourID); var addTours = worker.Tours.Where(c => !oldIds.Contains(c.ID)).ToList(); var newIds = worker.Tours.Select(c => c.ID); var removeTours = w.Tours.Where(c => !newIds.Contains(c.TourID)).ToList(); foreach (var item in removeTours) { var a = repositoryTour.Single(c => c.TourID == item.TourID); w.Tours.Remove(a); } foreach (var item in addTours) { var a = repositoryTour.Single(c => c.TourID == item.ID); w.Tours.Add(a); } repository.Update(w); unitOfWork.CommitTransaction(); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public void UpdateUser(Objects.User user) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <User> repository = new Repositor <User>(unitOfWork); IRepository <Role> repositoryRole = new Repositor <Role>(unitOfWork); try { ObjectValidator.IsValid(user); unitOfWork.BeginTransaction(); var u = repository.Single(c => c.UserID == user.ID); u.UserDetachmentID = user.DetachmentID; u.UserDescription = String.IsNullOrWhiteSpace(user.Description) ? null : user.Description; u.UserWorkerID = user.WorkerID; if (user.Roles != null) { var oldIds = u.Roles.Select(c => c.RoleID); var addRoles = user.Roles.Where(c => !oldIds.Contains(c.ID)).ToList(); var newIds = user.Roles.Select(c => c.ID); var removeRoles = u.Roles.Where(c => !newIds.Contains(c.RoleID)).ToList(); foreach (var item in removeRoles) { var r = repositoryRole.Single(c => c.RoleID == item.RoleID); u.Roles.Remove(r); } foreach (var item in addRoles) { var r = repositoryRole.Single(c => c.RoleID == item.ID); u.Roles.Add(r); } } repository.Update(u); unitOfWork.CommitTransaction(); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
protected virtual void EnsureRoles() { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <User> repository = new Repositor <User>(unitOfWork); try { roles = repository.Single(c => c.UserName == identities[0].Name).Roles.Select(c => c.RoleName).ToArray(); } catch (Exception e) { throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public void DeleteChangeover(Int32 changeoverID) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Changeover> repository = new Repositor <Changeover>(unitOfWork); try { unitOfWork.BeginTransaction(); var ch = repository.Single(c => c.ChangeoverID == changeoverID); repository.Delete(ch); unitOfWork.CommitTransaction(); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public void DeleteDetachment(Int32 detachmentID) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Detachment> repository = new Repositor <Detachment>(unitOfWork); try { unitOfWork.BeginTransaction(); var d = repository.Single(c => c.DetachmentID == detachmentID); repository.Delete(d); unitOfWork.CommitTransaction(); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public void DeleteWorker(int workerID) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Worker> repository = new Repositor <Worker>(unitOfWork); try { unitOfWork.BeginTransaction(); var w = repository.Single(c => c.WorkerID == workerID); repository.Delete(w); unitOfWork.CommitTransaction(); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public void DeleteVehicle(Int32 vehicleID) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Vehicle> repository = new Repositor <Vehicle>(unitOfWork); try { unitOfWork.BeginTransaction(); var v = repository.Single(c => c.VehicleID == vehicleID); repository.Delete(v); unitOfWork.CommitTransaction(); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public Objects.Detachment FindDetachment(Int32 detachmentID) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Detachment> repository = new Repositor <Detachment>(unitOfWork); try { var d = repository.Single(c => c.DetachmentID == detachmentID); Objects.Detachment detachment = new Objects.Detachment(); detachment.ID = d.DetachmentID; detachment.Name = d.DetachmentName; detachment.Description = d.DetachmentDescription; return(detachment); } catch (Exception e) { throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public void UpdateChangeover(Objects.Changeover changeover) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Changeover> repository = new Repositor <Changeover>(unitOfWork); try { ObjectValidator.IsValid(changeover); unitOfWork.BeginTransaction(); var ch = repository.Single(c => c.ChangeoverID == changeover.ID); ch.ChangeoverDescription = String.IsNullOrWhiteSpace(changeover.Description) ? null : changeover.Description; repository.Update(ch); unitOfWork.CommitTransaction(); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public void UpdateTour(Objects.Tour tour) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Tour> repository = new Repositor <Tour>(unitOfWork); try { ObjectValidator.IsValid(tour); unitOfWork.BeginTransaction(); var t = repository.Single(c => c.TourID == tour.ID); t.TourDescription = String.IsNullOrWhiteSpace(tour.Description) ? null : tour.Description; repository.Update(t); unitOfWork.CommitTransaction(); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public void UpdateDetachment(Objects.Detachment detachment) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Detachment> repository = new Repositor <Detachment>(unitOfWork); try { ObjectValidator.IsValid(detachment); unitOfWork.BeginTransaction(); var d = repository.Single(c => c.DetachmentID == detachment.ID); d.DetachmentDescription = String.IsNullOrWhiteSpace(detachment.Description) ? null : detachment.Description; repository.Update(d); unitOfWork.CommitTransaction(); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public bool ChangePassword(Objects.User user) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <User> repository = new Repositor <User>(unitOfWork); try { unitOfWork.BeginTransaction(); var u = repository.Single(c => c.UserID == user.ID); u.UserPassword = String.IsNullOrWhiteSpace(user.Password) ? null : user.Password; repository.Update(u); unitOfWork.CommitTransaction(); return(true); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public void UpdateWorkType(Objects.WorkType workType) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <WorkType> repository = new Repositor <WorkType>(unitOfWork); try { ObjectValidator.IsValid(workType); unitOfWork.BeginTransaction(); var wt = repository.Single(c => c.WorkTypeID == workType.ID); wt.WorkTypeDescription = String.IsNullOrWhiteSpace(workType.Description) ? null : workType.Description; repository.Update(wt); unitOfWork.CommitTransaction(); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public void UpdateVehicle(Objects.Vehicle vehicle) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Vehicle> repository = new Repositor <Vehicle>(unitOfWork); try { ObjectValidator.IsValid(vehicle); unitOfWork.BeginTransaction(); var v = repository.Single(c => c.VehicleID == vehicle.ID); v.VehicleDescription = String.IsNullOrWhiteSpace(vehicle.Description) ? null : vehicle.Description; repository.Update(v); unitOfWork.CommitTransaction(); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public Objects.Work TransferChangeover(Int64 dateID, Int32 changeoverID) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Changeover> repository = new Repositor <Changeover>(unitOfWork); IRepository <Work> workRepository = new Repositor <Work>(unitOfWork); try { unitOfWork.BeginTransaction(); var ch = repository.Single(c => c.ChangeoverID == changeoverID); Work w = new Work(); w.WorkDateID = dateID; w.WorkVehicleID = ch.ChangeoverVehicleID; w.WorkWorkTypeID = ch.ChangeoverWorkTypeID; w.WorkFaultDescription = String.IsNullOrWhiteSpace(ch.ChangeoverDescription) ? null : ch.ChangeoverDescription; workRepository.Add(w); repository.Delete(ch); unitOfWork.CommitTransaction(); w = workRepository.UoW.Orm.Set <Work>(). Include("Vehicle"). Include("Date"). Include("WorkType").Single(c => c.WorkID == w.WorkID); return(new Objects.Work() { DateContent = w.Date.DateDate, DateID = w.WorkDateID, FaultDescription = w.WorkFaultDescription, ID = w.WorkID, IsNight = w.Date.DateIsNight, VehicleID = w.WorkVehicleID, VehicleNumber = w.Vehicle.VehicleNumber, WorkTypeID = w.WorkWorkTypeID, WorkTypeName = w.WorkType.WorkTypeName }); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public string ResetPassword(Int32 userID) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <User> repository = new Repositor <User>(unitOfWork); try { unitOfWork.BeginTransaction(); var u = repository.Single(c => c.UserID == userID); PasswordGenerator generator = new PasswordGenerator(10, u.UserName); u.UserPassword = generator.Hash; repository.Update(u); unitOfWork.CommitTransaction(); return(generator.Password); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public void DeleteWork(Int64 workID) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Work> repository = new Repositor <Work>(unitOfWork); try { unitOfWork.BeginTransaction(); var w = repository.Single(c => c.WorkID == workID); if (w.Date.DateIsClosed) { throw new DateException("Směna je uzamčená, nelze odebírat ani editovat záznamy"); } repository.Delete(w); unitOfWork.CommitTransaction(); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public Objects.User AddUser(Objects.User user) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <User> repository = new Repositor <User>(unitOfWork); IRepository <Role> repositoryRole = new Repositor <Role>(unitOfWork); try { ObjectValidator.IsValid(user); PasswordGenerator generator = new PasswordGenerator(10, user.Name); user.Password = generator.Password; User u = new User(); u.UserName = String.IsNullOrWhiteSpace(user.Name) ? null : user.Name; u.UserPassword = generator.Hash; u.UserWorkerID = user.WorkerID; u.UserDetachmentID = user.DetachmentID; u.UserDescription = String.IsNullOrWhiteSpace(user.Description) ? null : user.Description; if (user.Roles != null) { foreach (var item in user.Roles) { var r = repositoryRole.Single(c => c.RoleID == item.ID); u.Roles.Add(r); } } unitOfWork.BeginTransaction(); repository.Add(u); unitOfWork.CommitTransaction(); user.ID = u.UserID; return(user); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public Int32 AddWorker(Objects.WorkerDetail worker) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Worker> repository = new Repositor <Worker>(unitOfWork); IRepository <Tour> repositoryTour = new Repositor <Tour>(unitOfWork); try { ObjectValidator.IsValid(worker); Worker w = new Worker(); w.WorkerFirstName = String.IsNullOrWhiteSpace(worker.FirstName) ? null : worker.FirstName; w.WorkerLastName = String.IsNullOrWhiteSpace(worker.LastName) ? null : worker.LastName; w.WorkerServiceNumber = String.IsNullOrWhiteSpace(worker.ServiceNumber) ? null : worker.ServiceNumber; w.WorkerSapNumber = String.IsNullOrWhiteSpace(worker.SapNumber) ? null : worker.SapNumber; w.WorkerServiceEmail = String.IsNullOrWhiteSpace(worker.ServiceEmail) ? null : worker.ServiceEmail; w.WorkerPersonalEmail = String.IsNullOrWhiteSpace(worker.PersonalEmail) ? null : worker.PersonalEmail; w.WorkerServicePhone = String.IsNullOrWhiteSpace(worker.ServicePhone) ? null : worker.ServicePhone; w.WorkerPersonalPhone = String.IsNullOrWhiteSpace(worker.PersonalPhone) ? null : worker.PersonalPhone; w.WorkerDescription = String.IsNullOrWhiteSpace(worker.Description) ? null : worker.Description; w.WorkerPhoto = worker.Photo; w.WorkerDetachmentID = worker.DetachmentID; foreach (var item in worker.Tours) { var t = repositoryTour.Single(c => c.TourID == item.ID); w.Tours.Add(t); } unitOfWork.BeginTransaction(); repository.Add(w); unitOfWork.CommitTransaction(); return(w.WorkerID); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public override void Validate(string userName, string password) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <User> repository = new Repositor <User>(unitOfWork); if (String.IsNullOrEmpty(userName) || String.IsNullOrEmpty(password)) { logger.Log(LogLevel.Warn, "Not authentication"); throw new SecurityTokenException("Nesprávně zadané heslo nebo jméno!"); } try { var user = repository.Single(c => c.UserName == userName && c.UserPassword == password); if (user == null) { logger.Log(LogLevel.Warn, "Not authentication"); throw new SecurityTokenException("Nesprávně zadané heslo nebo jméno!"); } } catch (Exception e) { throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }