Example #1
0
        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));
            }
        }
Example #2
0
        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));
            }
        }
Example #3
0
        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));
            }
        }