public void Handle(EditWaiterCommand command)
        {
            if (UnitOfWork.AnyActual <Waiter>(x => x.User.Login == command.Login && x.Id != command.Id))
            {
                throw new InvalidOperationException("Waiter with the same login exists.");
            }

            var currentTable = UnitOfWork.Get <Waiter>(command.Id);

            if (!currentTable.IsNewest)
            {
                throw new InvalidOperationException("You cant edit not newest waiter.");
            }

            if (currentTable.IsDeleted)
            {
                throw new InvalidOperationException("You cant edit deleted waiter.");
            }

            var newVersion = (Waiter)currentTable.CreateNewVersion(UnitOfWork);

            newVersion.FirstName = command.FirstName;
            newVersion.LastName  = command.LastName;

            if (newVersion.User.Login != command.Login)
            {
                var user = (User)newVersion.User.CreateNewVersion(UnitOfWork);
                user.Login = command.Login;

                newVersion.User = user;
            }
        }
Esempio n. 2
0
        public void Handle(EditTableCommand command)
        {
            if (UnitOfWork.AnyActual <Table>(x => x.Title == command.Title && x.Id != command.Id))
            {
                throw new InvalidOperationException("Table with the same name exists.");
            }

            var currentTable = UnitOfWork.Get <Table>(command.Id);

            if (!currentTable.IsNewest)
            {
                throw new InvalidOperationException("You cant edit not newest table.");
            }

            if (currentTable.IsDeleted)
            {
                throw new InvalidOperationException("You cant edit deleted table.");
            }

            var newVersion = (Table)currentTable.CreateNewVersion(UnitOfWork);

            newVersion.Title       = command.Title;
            newVersion.Description = command.Description;

            if (newVersion.User.Login != command.Title)
            {
                var user = (User)newVersion.User.CreateNewVersion(UnitOfWork);
                user.Login = command.Title;

                newVersion.User = user;
            }
        }
Esempio n. 3
0
        public void Handle(AddTableCommand command)
        {
            if (UnitOfWork.AnyActual <Table>(x => x.Title == command.Title))
            {
                throw new InvalidOperationException("Table with the same name exists.");
            }

            var login      = command.Title;
            var secondHash = _passwordManager.CreateSecondHash(login, command.Password);

            var addedUser = UnitOfWork.Add(new User()
            {
                SecondHash = secondHash, Login = login
            });

            UnitOfWork.Add(new Table {
                Title = command.Title, Description = command.Description, User = addedUser
            });
        }
        public void Handle(AddWaiterCommand command)
        {
            if (UnitOfWork.AnyActual <Waiter>(x => x.User.Login == command.Login))
            {
                throw new InvalidOperationException("Waiter with the same login exists.");
            }

            var secondHash = _passwordManager.CreateSecondHash(command.Login, command.Password);

            var addedUser = UnitOfWork.Add(new User()
            {
                SecondHash = secondHash, Login = command.Login
            });

            UnitOfWork.Add(new Waiter()
            {
                FirstName = command.FirstName, LastName = command.LastName, User = addedUser
            });
        }
        public void Handle(AddWebClientCommand command)
        {
            if (UnitOfWork.AnyActual <WebClient>(x => x.User.Login == command.Login))
            {
                throw new InvalidOperationException("Table with the same name exists.");
            }

            var login      = command.Login;
            var secondHash = _passwordManager.CreateSecondHashFromFirst(command.FirstHash);

            var addedUser = UnitOfWork.Add(new User()
            {
                SecondHash = secondHash, Login = login
            });

            UnitOfWork.Add(new WebClient {
                FirstName = command.FirstHash, LastName = command.LastName, Phone = command.Phone, Mail = command.Mail, User = addedUser
            });
        }