コード例 #1
0
        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));
            }
        }
コード例 #2
0
        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));
            }
        }
コード例 #3
0
        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));
            }
        }
コード例 #4
0
        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));
            }
        }
コード例 #5
0
        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));
            }
        }
コード例 #6
0
        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));
            }
        }
コード例 #7
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));
            }
        }
コード例 #8
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));
            }
        }
コード例 #9
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));
            }
        }
コード例 #10
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));
            }
        }
コード例 #11
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));
            }
        }
コード例 #12
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));
            }
        }
コード例 #13
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));
            }
        }
コード例 #14
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));
            }
        }
コード例 #15
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));
            }
        }
コード例 #16
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));
            }
        }
コード例 #17
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));
            }
        }
コード例 #18
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));
            }
        }
コード例 #19
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));
            }
        }