Пример #1
0
        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));
            }
        }
Пример #2
0
        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));
            }
        }
Пример #3
0
        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));
            }
        }
Пример #4
0
        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));
            }
        }
Пример #5
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));
            }
        }
Пример #6
0
        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));
            }
        }
Пример #7
0
        public Int32 AddDetachment(Objects.Detachment detachment)
        {
            IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork;
            IRepository <Detachment> repository = new Repositor <Detachment>(unitOfWork);

            try
            {
                ObjectValidator.IsValid(detachment);
                Detachment d = new Detachment();
                d.DetachmentName        = String.IsNullOrWhiteSpace(detachment.Name) ? null : detachment.Name;
                d.DetachmentDescription = String.IsNullOrWhiteSpace(detachment.Description) ? null : detachment.Description;
                unitOfWork.BeginTransaction();
                repository.Add(d);
                unitOfWork.CommitTransaction();
                return(d.DetachmentID);
            }
            catch (Exception e)
            {
                unitOfWork.RollbackTransaction();
                throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e));
            }
        }
Пример #8
0
        public Int32 AddVehicle(Objects.Vehicle vehicle)
        {
            IUnitOfWork           unitOfWork = SessionFactory.GetUnitOfWork;
            IRepository <Vehicle> repository = new Repositor <Vehicle>(unitOfWork);

            try
            {
                ObjectValidator.IsValid(vehicle);
                Vehicle v = new Vehicle();
                v.VehicleNumber       = String.IsNullOrWhiteSpace(vehicle.Number) ? null : vehicle.Number;
                v.VehicleDescription  = String.IsNullOrWhiteSpace(vehicle.Description) ? null : vehicle.Description;
                v.VehicleDetachmentID = vehicle.DetachmentID;
                unitOfWork.BeginTransaction();
                repository.Add(v);
                unitOfWork.CommitTransaction();
                return(v.VehicleID);
            }
            catch (Exception e)
            {
                unitOfWork.RollbackTransaction();
                throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e));
            }
        }
Пример #9
0
        public void DeleteAttendance(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");
                }
                repository.Delete(a);
                unitOfWork.CommitTransaction();
            }
            catch (Exception e)
            {
                unitOfWork.RollbackTransaction();
                throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e));
            }
        }
Пример #10
0
        public Int32 AddWorkType(Objects.WorkType workType)
        {
            IUnitOfWork            unitOfWork = SessionFactory.GetUnitOfWork;
            IRepository <WorkType> repository = new Repositor <WorkType>(unitOfWork);

            try
            {
                ObjectValidator.IsValid(workType);
                WorkType wt = new WorkType();
                wt.WorkTypeName         = String.IsNullOrWhiteSpace(workType.Name) ? null : workType.Name;
                wt.WorkTypeDescription  = String.IsNullOrWhiteSpace(workType.Description) ? null : workType.Description;
                wt.WorkTypeDetachmentID = workType.DetachmentID;
                unitOfWork.BeginTransaction();
                repository.Add(wt);
                unitOfWork.CommitTransaction();
                return(wt.WorkTypeID);
            }
            catch (Exception e)
            {
                unitOfWork.RollbackTransaction();
                throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e));
            }
        }
Пример #11
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));
            }
        }
Пример #12
0
        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));
            }
        }
Пример #13
0
        public Int32 AddTour(Objects.Tour tour)
        {
            IUnitOfWork        unitOfWork = SessionFactory.GetUnitOfWork;
            IRepository <Tour> repository = new Repositor <Tour>(unitOfWork);

            try
            {
                ObjectValidator.IsValid(tour);
                Tour t = new Tour();
                t.TourStartTime    = tour.StartTime;
                t.TourEndTime      = tour.EndTime;
                t.TourDetachmentID = tour.DetachmentID;
                t.TourDescription  = String.IsNullOrWhiteSpace(tour.Description) ? null : tour.Description;
                unitOfWork.BeginTransaction();
                repository.Add(t);
                unitOfWork.CommitTransaction();
                return(t.TourID);
            }
            catch (Exception e)
            {
                unitOfWork.RollbackTransaction();
                throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e));
            }
        }
Пример #14
0
        public void AddAttendance(Objects.Attendance attendance)
        {
            IUnitOfWork unitOfWork = SessionFactory.GetUnitOfWork;
            IRepository <Attendance> repository = new Repositor <Attendance>(unitOfWork);

            try
            {
                ObjectValidator.IsValid(attendance);
                Attendance a = new Attendance();
                a.AttendanceDateID        = attendance.DateID;
                a.AttendanceWorkerID      = attendance.WorkerID;
                a.AttendanceWorkerStateID = attendance.WorkerStateID;
                a.AttendanceDescription   = String.IsNullOrWhiteSpace(attendance.Description) ? null : attendance.Description;
                a.AttendanceWorkerTourID  = attendance.WorkerTourID;
                unitOfWork.BeginTransaction();
                repository.Add(a);
                unitOfWork.CommitTransaction();
            }
            catch (Exception e)
            {
                unitOfWork.RollbackTransaction();
                throw new FaultException <WcfException>(ExceptionProvider.CreateFaultContract(e));
            }
        }