Example #1
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));
            }
        }
Example #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));
            }
        }
Example #3
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));
            }
        }
Example #4
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));
            }
        }
Example #5
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));
            }
        }
Example #6
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));
            }
        }
Example #7
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));
            }
        }
Example #8
0
        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));
            }
        }
Example #9
0
        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));
            }
        }
Example #10
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 #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));
            }
        }