Beispiel #1
0
        public void UpdateWorker(WorkerView updated, WorkerView toUpdate)
        {
            if (!IsUserLoggedIn)
            {
                throw new UserLoggedInException();
            }

            Worker upTo = ViewConverter.CreateWorker(updated);

            try
            {
                workers.Open();
                if (!workers.UpdateWorker(toUpdate.Id, upTo))
                {
                    workers.Close();
                    throw new WorkerUpdateFailedException();
                }
                if (currentUser.Id == toUpdate.Id)
                {
                    WorkerUpdated?.Invoke(this, ViewConverter.CreateWorkerView(workers.GetById(currentUser.Id)));
                }
                workers.Close();
            }
            catch (DAL.Repositorys.PrimeryKeyAllReadyExistException e)
            {
                log.Exception(e);
                throw new util.PrimeryKeyAllReadyExistException();
            }catch (RepositoryOpenFailedExceptiom e)
            {
                log.Exception(e, "Failed on tring to update a user.");
                log.Fetal("Fetal Error, App shuting down.");
                Shutdown(1);
                return;
            }catch (RepositorySaveFailedExceptiom e)
            {
                log.Exception(e, "Failed on tring to update a user.");
                log.Fetal("Fetal Error, App shuting down.");
                Shutdown(1);
                return;
            }
            catch (Exception e)
            {
                log.Exception(e, "Unknown exception, Closing App.");
                Shutdown(1);
                return;
            }
            finally
            {
                workers.Close();
            }
        }
Beispiel #2
0
        public IEnumerable <WorkerLabel> GetWorkers(params Predicate <WorkerView>[] predicates)
        {
            if (UserRank == WorkerView.Rank.Manager)
            {
                try
                {
                    workers.Open();
                }
                catch (RepositoryOpenFailedExceptiom e)
                {
                    log.Exception(e, "Failed on tring to get users.");
                    log.Fetal("Fetal Error, App shuting down.");
                    Shutdown(1);
                }
                List <WorkerLabel> list = new List <WorkerLabel>();
                foreach (var item in workers.GetAll())
                {
                    var  itemView = ViewConverter.CreateWorkerView(item);
                    bool found    = false;
                    foreach (var pred in predicates)
                    {
                        if (pred(itemView))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        list.Add(ViewConverter.CreateWorkerLabel(itemView));
                    }
                }
                try
                {
                    workers.Close();
                }
                catch (RepositorySaveFailedExceptiom e)
                {
                    log.Exception(e, "Failed on tring to get all the users.");
                    log.Fetal("Fetal Error, App shuting down.");
                    Shutdown(1);
                }
                return(list);
            }
            else
            {
                throw new UserAccessException("You dont have access to Workes Reposetory.");
            }
        }
Beispiel #3
0
        public void RemoveWorker(int id)
        {
            if (!IsUserLoggedIn)
            {
                throw new UserLoggedInException();
            }

            if (currentUser.WorkerRank != WorkerView.Rank.Manager)
            {
                throw new UserAccessException($"{WorkerView.Rank.Manager} Access needed for that action, your Access is {currentUser.WorkerRank}.");
            }

            Worker worker;

            try
            {
                workers.Open();
            }catch (RepositoryOpenFailedExceptiom e)
            {
                log.Exception(e, "Failed on tring to update a user.");
                log.Fetal("Fetal Error, App shuting down.");
                Shutdown(1);
            }
            if (workers.RemoveById(id, out worker))
            {
                try
                {
                    workers.Close();
                }
                catch (RepositorySaveFailedExceptiom e)
                {
                    log.Exception(e, "Failed on tring to get user.");
                    log.Fetal("Fetal Error, App shuting down.");
                    Shutdown(1);
                }
                WorkerRemoved?.Invoke(this, ViewConverter.CreateWorkerView(worker));
            }
        }
 public UserLoggedInEventArgs(Worker work)
 {
     Worker       = ViewConverter.CreateWorkerView(work);
     IsManager    = (Worker.WorkerRank == ViewModel.Models.WorkerView.Rank.Manager);
     LoggedInTime = DateTime.Now;
 }
Beispiel #5
0
        public WorkerView GetUserView(int i)
        {
            if (currentUser.Id == i)
            {
                try
                {
                    workers.Open();
                    Worker w = workers.GetById(i);
                    workers.Close();
                    return(ViewConverter.CreateWorkerView(w));
                }
                catch (ItemNotFoundException e)
                {
                    log.Exception(e);
                }catch (RepositoryOpenFailedExceptiom e)
                {
                    log.Exception(e, "Failed on tring to get a user view.");
                    log.Fetal("Fetal Error, App shuting down.");
                    Shutdown(1);
                }catch (RepositorySaveFailedExceptiom e)
                {
                    log.Exception(e, "Failed on tring to get user.");
                    log.Fetal("Fetal Error, App shuting down.");
                    Shutdown(1);
                }
                catch (RepositoryCloesedException e)
                {
                    log.Exception(e);
                }
                finally
                {
                    try
                    {
                        workers.Close();
                    }
                    catch (RepositorySaveFailedExceptiom e)
                    {
                        log.Exception(e, "Failed on tring to get user.");
                        log.Fetal("Fetal Error, App shuting down.");
                        Shutdown(1);
                    }
                }
            }
            if (currentUser.WorkerRank == WorkerView.Rank.Manager)
            {
                try
                {
                    workers.Open();
                    Worker w = workers.GetById(i);
                    try
                    {
                        workers.Close();
                    }
                    catch (RepositorySaveFailedExceptiom e)
                    {
                        log.Exception(e, "Failed on tring to get user.");
                        log.Fetal("Fetal Error, App shuting down.");
                        Shutdown(1);
                    }
                    return(ViewConverter.CreateWorkerView(w));
                }
                catch (ItemNotFoundException e)
                {
                    log.Exception(e);
                }
                catch (RepositoryCloesedException e)
                {
                    log.Exception(e);
                }
                catch (Exception e)
                {
                    log.Exception(e, "What just Hapend?");
                    Shutdown(1);
                }
                finally
                {
                    try
                    {
                        workers.Close();
                    }
                    catch (RepositorySaveFailedExceptiom e)
                    {
                        log.Exception(e, "Failed on tring to get user.");
                        log.Fetal("Fetal Error, App shuting down.");
                        Shutdown(1);
                    }
                }
                ;
            }

            throw new UserAccessException("You dont have access to that user.");
        }