public Int32 AddChangeover(Objects.Changeover changeover) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Changeover> repository = new Repositor <Changeover>(unitOfWork); try { ObjectValidator.IsValid(changeover); Changeover ch = new Changeover(); ch.ChangeoverDateID = changeover.DateID; ch.ChangeoverVehicleID = changeover.VehicleID; ch.ChangeoverWorkTypeID = changeover.WorkTypeID; ch.ChangeoverDescription = String.IsNullOrWhiteSpace(changeover.Description) ? null : changeover.Description; ch.ChangeoverDetachmentID = changeover.DetachmentID; unitOfWork.BeginTransaction(); repository.Add(ch); unitOfWork.CommitTransaction(); return(ch.ChangeoverID); } catch (Exception e) { unitOfWork.RollbackTransaction(); throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
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 Int64 AddDate(Objects.Date date) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Date> repository = new Repositor <Date>(unitOfWork); try { ObjectValidator.IsValid(date); Date d = new Date(); d.DateDate = date.DateContent; d.DateIsNight = date.IsNight; d.DateIsClosed = false; d.DateDetachmentID = date.DetachmentID; d.DateDescription = String.IsNullOrWhiteSpace(date.Description) ? null : date.Description; unitOfWork.BeginTransaction(); var de = repository.Find(c => c.DateDate.Date >= date.DateContent.Date && c.DateDetachmentID == date.DetachmentID).ToList(); if (de != null) { if (de.Any(c => c.DateDate.Date > date.DateContent.Date) || de.Any(c => c.DateDate.Date == date.DateContent.Date && c.DateIsNight == true)) { throw new FormatException("Není možné vytvářet směnu zpětně!"); } } repository.Add(d); unitOfWork.CommitTransaction(); return(d.DateID); } 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 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)); } }
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 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 List <Objects.User> GetUsers() { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <User> repository = new Repositor <User>(unitOfWork); try { return(repository.GetAll().Select(c => new Objects.User() { ID = c.UserID, Name = c.UserName, WorkerID = c.UserWorkerID, Description = c.UserDescription, DetachmentID = c.UserDetachmentID, Roles = c.Roles.Select(r => new Objects.Role() { ID = r.RoleID, Name = r.RoleName }) }).ToList()); } catch (Exception e) { throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public List <Objects.Changeover> FindChangeovers(Int32 detachmentID) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Changeover> repository = new Repositor <Changeover>(unitOfWork); try { return(repository.Find(c => c.ChangeoverDetachmentID == detachmentID).Select(c => new Objects.Changeover() { ID = c.ChangeoverID, DateID = c.ChangeoverDateID, DateContent = c.Date.DateDate, IsNight = c.Date.DateIsNight, VehicleID = c.ChangeoverVehicleID, VehicleNumber = c.Vehicle.VehicleNumber, WorkTypeID = c.ChangeoverWorkTypeID, WorkTypeName = c.WorkType.WorkTypeName, Description = c.ChangeoverDescription, DetachmentID = c.ChangeoverDetachmentID }).ToList()); } catch (Exception e) { throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public List <Objects.Attendance> FindAttendances(Int64 dateID) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Attendance> repository = new Repositor <Attendance>(unitOfWork); try { return(repository.Find(k => k.AttendanceDateID == dateID).Select(c => new Objects.Attendance() { DateID = c.AttendanceDateID, WorkerID = c.AttendanceWorkerID, FirstName = c.Worker.WorkerFirstName, LastName = c.Worker.WorkerLastName, SapNumber = c.Worker.WorkerSapNumber, WorkerStateID = c.AttendanceWorkerStateID, WorkerState = c.WorkerState.WorkerStateName, WorkerTourID = c.AttendanceWorkerTourID, WorkerTour = c.Tour.TourStartTime.ToString("hh\\:mm") + " - " + c.Tour.TourEndTime.ToString("hh\\:mm"), Description = c.AttendanceDescription }).ToList()); } catch (Exception e) { throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e)); } }
public List <Int32> GetMonths(int year, Int32 detachmentID) { try { using (Entities context = new Entities()) { return(context.Months(year, detachmentID).Select(c => c.Value).OrderBy(c => c).ToList <Int32>()); } } catch (Exception e) { 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 List <string> GetTopCauseWorks(Int32 count, Int32 detachmentID) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Work> repository = new Repositor <Work>(unitOfWork); try { return(repository.Find(c => c.Date.DateDetachmentID == detachmentID). GroupBy(c => c.WorkCauseDescription).OrderByDescending( c => c.Count()).Select(c => c.Key).Take(count).ToList()); } 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 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 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 List <Objects.Role> GetRoles() { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Role> repository = new Repositor <Role>(unitOfWork); try { return(repository.GetAll().Select(c => new Objects.Role() { ID = c.RoleID, Name = c.RoleName }).ToList()); } catch (Exception e) { 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 List <Objects.Detachment> GetDetachments() { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Detachment> repository = new Repositor <Detachment>(unitOfWork); try { return(repository.GetAll().Select(c => new Objects.Detachment() { ID = c.DetachmentID, Name = c.DetachmentName, Description = c.DetachmentDescription }).ToList()); } catch (Exception e) { 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 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 List <Objects.Vehicle> FindVehicles(Int32 detachmentID) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Vehicle> repository = new Repositor <Vehicle>(unitOfWork); try { return(repository.Find(c => c.VehicleDetachmentID == detachmentID).Select(c => new Objects.Vehicle() { ID = c.VehicleID, Number = c.VehicleNumber, DetachmentID = c.VehicleDetachmentID, Description = c.VehicleDescription }).ToList()); } 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 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 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 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 List <Objects.Tour> FindTours(Int32 detachmentID) { IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork; IRepository <Tour> repository = new Repositor <Tour>(unitOfWork); try { return(repository.Find(c => c.TourDetachmentID == detachmentID).Select(c => new Objects.Tour() { ID = c.TourID, EndTime = c.TourEndTime, StartTime = c.TourStartTime, DetachmentID = c.TourDetachmentID, Description = c.TourDescription }).ToList()); } catch (Exception e) { 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)); } }