Exemple #1
0
        public ErrorAppRemax Remove(int houseId)
        {
            ErrorAppRemax err = new ErrorAppRemax();

            // TODO: check whether the House has ever taken part in any Sale transaction.

            // result is the number of affected rows.
            int result = DataSource.DeleteHouse(houseId);

            // Any error occurred?
            if (DataSource.ErrorCode() != 0)
            {
                err.ErrorCode    = DataSource.ErrorCode();
                err.ErrorMessage = DataSource.ErrorMessage();
                return(err);
            }

            if (result == 1)
            {
                // If the deleting works fine only one row should be affected.

                _list.Remove(houseId);

                return(err);
            }
            else
            {
                err.ErrorCode    = -1;
                err.ErrorMessage = $"The delete operation was not successful ({result} rows affected). Please check the database.";
                return(err);
            }
        }
Exemple #2
0
        public ErrorAppRemax Save(House house)
        {
            ErrorAppRemax err = new ErrorAppRemax();

            // result is the number of affected rows.
            int result = DataSource.UpdateHouse(house.HouseId, (int)house.BuildingType, house.Street, house.ApartmentNo,
                                                house.PostalCode, house.Country, house.MakingYear, house.Bathrooms, house.Bedrooms, house.Area, house.Description,
                                                house.Price, house.Tax, house.Seller.ClientId);

            // Any error occurred?
            if (DataSource.ErrorCode() != 0)
            {
                err.ErrorCode    = DataSource.ErrorCode();
                err.ErrorMessage = DataSource.ErrorMessage();
                return(err);
            }

            if (result == 1)
            {
                // If the updating works fine only one row should be affected.

                // Locating the corresponding House object inside _list.
                House existingHouse = FindByHouseId(house.HouseId);
                // Updating the House object inside _list.
                existingHouse.HouseId      = house.HouseId;
                existingHouse.BuildingType = house.BuildingType;
                existingHouse.Street       = house.Street;
                existingHouse.ApartmentNo  = house.ApartmentNo;
                existingHouse.PostalCode   = house.PostalCode;
                existingHouse.Country      = house.Country;
                existingHouse.MakingYear   = house.MakingYear;
                existingHouse.Bathrooms    = house.Bathrooms;
                existingHouse.Bedrooms     = house.Bedrooms;
                existingHouse.Area         = house.Area;
                existingHouse.Description  = house.Description;
                existingHouse.Price        = house.Price;
                existingHouse.Tax          = house.Tax;
                existingHouse.Seller       = house.Seller;

                return(err);
            }
            else
            {
                err.ErrorCode    = -1;
                err.ErrorMessage = $"The save operation was not successful ({result} rows affected). Please check the database.";
                return(err);
            }
        }
        public ErrorAppRemax Add(Employee employee)
        {
            ErrorAppRemax err = new ErrorAppRemax();

            if (_list.ContainsKey(employee.EmployeeId))
            {
                err.ErrorCode    = -1;
                err.ErrorMessage = "There is another Employee with this same Employee Id.";
                return(err);
            }

            // Checking whether there is another Employee with the same Username.
            if (FindByUsername(employee.Username) != null)
            {
                err.ErrorCode    = -1;
                err.ErrorMessage = "There is another Employee with this same Username.";
                return(err);
            }

            // result is the number of affected rows.
            // The initial password is equal to the Username.
            int result = DataSource.AddEmployee(employee.FirstName, employee.LastName, employee.BirthDate,
                                                employee.Email, employee.Phone, (int)employee.Position, employee.Salary, employee.Username, employee.Username);

            // Any error occurred?
            if (DataSource.ErrorCode() != 0)
            {
                err.ErrorCode    = DataSource.ErrorCode();
                err.ErrorMessage = DataSource.ErrorMessage();
                return(err);
            }

            if (result == 1)
            {
                // If the adding works fine only one row should be affected.

                // Reloading _list.
                LoadEmployees();

                return(err);
            }
            else
            {
                err.ErrorCode    = -1;
                err.ErrorMessage = $"The add operation was not successful ({result} rows affected). Please check the database.";
                return(err);
            }
        }
        public ErrorAppRemax Remove(int employeeId)
        {
            ErrorAppRemax err = new ErrorAppRemax();

            // **** Checking whether the Employee being removed is assigned to any Client as an Agent.
            // Retrieving the Employee.
            Employee employee = FindByEmployeeId(employeeId);
            // Retrieving the list of Clients for which the Employee is assigned as an Agent.
            List <Client> lstClients = (new ClientList()).GetClientsByAgent(employee);

            // If there is any Client then the Employee cannot be removed.
            if (lstClients.Count != 0)
            {
                err.ErrorCode    = -1;
                err.ErrorMessage = $"This Employee cannot be removed. She/he is the Agent of one or more Clients.";
                return(err);
            }

            // result is the number of affected rows.
            int result = DataSource.DeleteEmployee(employeeId);

            // Any error occurred?
            if (DataSource.ErrorCode() != 0)
            {
                err.ErrorCode    = DataSource.ErrorCode();
                err.ErrorMessage = DataSource.ErrorMessage();
                return(err);
            }

            if (result == 1)
            {
                // If the deleting works fine only one row should be affected.

                _list.Remove(employeeId);

                return(err);
            }
            else
            {
                err.ErrorCode    = -1;
                err.ErrorMessage = $"The delete operation was not successful ({result} rows affected). Please check the database.";
                return(err);
            }
        }
Exemple #5
0
        public ErrorAppRemax Remove(int clientId)
        {
            ErrorAppRemax err = new ErrorAppRemax();

            // **** Checking whether the Client being removed is the Seller of any House.
            // Retrieving the Client.
            Client client = FindByClientId(clientId);
            // Retrieving the list of Houses for which the Client is the Seller.
            List <House> lstHouses = (new HouseList()).GetHousesBySeller(client);

            // If there is any House then the Client cannot be removed.
            if (lstHouses.Count != 0)
            {
                err.ErrorCode    = -1;
                err.ErrorMessage = $"This Client cannot be removed. She/he is the Seller of one or more Houses.";
                return(err);
            }

            // result is the number of affected rows.
            int result = DataSource.DeleteClient(clientId);

            // Any error occurred?
            if (DataSource.ErrorCode() != 0)
            {
                err.ErrorCode    = DataSource.ErrorCode();
                err.ErrorMessage = DataSource.ErrorMessage();
                return(err);
            }

            if (result == 1)
            {
                // If the deleting works fine only one row should be affected.

                _list.Remove(clientId);

                return(err);
            }
            else
            {
                err.ErrorCode    = -1;
                err.ErrorMessage = $"The delete operation was not successful ({result} rows affected). Please check the database.";
                return(err);
            }
        }
Exemple #6
0
        public ErrorAppRemax Add(House house)
        {
            ErrorAppRemax err = new ErrorAppRemax();

            if (_list.ContainsKey(house.HouseId))
            {
                err.ErrorCode    = -1;
                err.ErrorMessage = "There is another House with this same House Id.";
                return(err);
            }

            // result is the number of affected rows.
            int result = DataSource.AddHouse((int)house.BuildingType, house.Street, house.ApartmentNo, house.PostalCode,
                                             house.Country, house.MakingYear, house.Bathrooms, house.Bedrooms, house.Area, house.Description, house.Price,
                                             house.Tax, house.Seller.ClientId);

            // Any error occurred?
            if (DataSource.ErrorCode() != 0)
            {
                err.ErrorCode    = DataSource.ErrorCode();
                err.ErrorMessage = DataSource.ErrorMessage();
                return(err);
            }

            if (result == 1)
            {
                // If the adding works fine only one row should be affected.

                // Reloading _list.
                LoadHouses();

                return(err);
            }
            else
            {
                err.ErrorCode    = -1;
                err.ErrorMessage = $"The add operation was not successful ({result} rows affected). Please check the database.";
                return(err);
            }
        }
Exemple #7
0
        public ErrorAppRemax Save(Client client)
        {
            ErrorAppRemax err = new ErrorAppRemax();

            // result is the number of affected rows.
            int result = DataSource.UpdateClient(client.ClientId, client.FirstName, client.LastName, client.BirthDate,
                                                 client.Email, client.Phone, (int)client.ClientType, client.Agent.EmployeeId);

            // Any error occurred?
            if (DataSource.ErrorCode() != 0)
            {
                err.ErrorCode    = DataSource.ErrorCode();
                err.ErrorMessage = DataSource.ErrorMessage();
                return(err);
            }

            if (result == 1)
            {
                // If the updating works fine only one row should be affected.

                // Locating the corresponding Client object inside _list.
                Client existingClient = FindByClientId(client.ClientId);
                // Updating the Client object inside _list.
                existingClient.FirstName  = client.FirstName;
                existingClient.LastName   = client.LastName;
                existingClient.BirthDate  = client.BirthDate;
                existingClient.Email      = client.Email;
                existingClient.Phone      = client.Phone;
                existingClient.ClientType = client.ClientType;
                existingClient.Agent      = client.Agent;

                return(err);
            }
            else
            {
                err.ErrorCode    = -1;
                err.ErrorMessage = $"The save operation was not successful ({result} rows affected). Please check the database.";
                return(err);
            }
        }
Exemple #8
0
        public ErrorAppRemax Add(Client client)
        {
            ErrorAppRemax err = new ErrorAppRemax();

            if (_list.ContainsKey(client.ClientId))
            {
                err.ErrorCode    = -1;
                err.ErrorMessage = "There is another Client with this same Client Id.";
                return(err);
            }

            // result is the number of affected rows.
            int result = DataSource.AddClient(client.FirstName, client.LastName, client.BirthDate,
                                              client.Email, client.Phone, (int)client.ClientType, client.Agent.EmployeeId);

            // Any error occurred?
            if (DataSource.ErrorCode() != 0)
            {
                err.ErrorCode    = DataSource.ErrorCode();
                err.ErrorMessage = DataSource.ErrorMessage();
                return(err);
            }

            if (result == 1)
            {
                // If the adding works fine only one row should be affected.

                // Reloading _list.
                LoadClients();

                return(err);
            }
            else
            {
                err.ErrorCode    = -1;
                err.ErrorMessage = $"The add operation was not successful ({result} rows affected). Please check the database.";
                return(err);
            }
        }
        public ErrorAppRemax Save(Employee employee)
        {
            ErrorAppRemax err = new ErrorAppRemax();

            // **** Checking whether the Employee:
            // 1. Is being saved with a Position different than Agent.
            // 2. Is already assigned to any Client as an Agent.
            // If this is the case then the Employee cannot be changed to another Position.

            // Retrieving the Position of the Employee being saved.
            Position position = employee.Position;

            // If the Employee is not being saved as an Agent...
            if (position != Position.Agent)
            {
                // ...need to check whether she/he has any client assigned.

                // Retrieving the list of Clients for which the Employee is assigned as an Agent.
                List <Client> lstClients = (new ClientList()).GetClientsByAgent(employee);

                // If there is any Client then the Employee cannot be changed to a Position other than Agent.
                if (lstClients.Count != 0)
                {
                    err.ErrorCode    = -1;
                    err.ErrorMessage = $"This Employee is the Agent of {lstClients.Count} Clients. The Position cannot be changed.";
                    return(err);
                }
            }

            // Updating the Employee.
            // result is the number of affected rows.
            int result = DataSource.UpdateEmployee(employee.EmployeeId, employee.FirstName, employee.LastName, employee.BirthDate,
                                                   employee.Email, employee.Phone, (int)employee.Position, employee.Salary);

            // Any error occurred?
            if (DataSource.ErrorCode() != 0)
            {
                err.ErrorCode    = DataSource.ErrorCode();
                err.ErrorMessage = DataSource.ErrorMessage();
                return(err);
            }

            if (result == 1)
            {
                // If the updating works fine only one row should be affected.

                // Locating the corresponding Employee object inside _list.
                Employee existingEmployee = FindByEmployeeId(employee.EmployeeId);
                // Updating the Employee object inside _list.
                existingEmployee.FirstName = employee.FirstName;
                existingEmployee.LastName  = employee.LastName;
                existingEmployee.BirthDate = employee.BirthDate;
                existingEmployee.Email     = employee.Email;
                existingEmployee.Phone     = employee.Phone;
                existingEmployee.Position  = employee.Position;
                existingEmployee.Salary    = employee.Salary;

                return(err);
            }
            else
            {
                err.ErrorCode    = -1;
                err.ErrorMessage = $"The save operation was not successful ({result} rows affected). Please check the database.";
                return(err);
            }
        }