Beispiel #1
0
        public bool CreateCustomerFare(double locX, double locY, string addrStreet, int addrNumber, string addrCity, int addrPostalCode, long customer, int type, DateTime date, out string report)
        {
            report = string.Empty;
            bool retVal = false;

            try
            {
                Model.Location loc  = new Model.Location(locX, locY);
                Model.Address  addr = new Model.Address(addrStreet, addrNumber, addrCity, addrPostalCode);
                loc.Address = addr.Id;
                Model.Fare fare = new Model.Fare(loc.Id, customer, type, date);
                var        user = DataManager.DataManager.Instance.GetById <Model.User>(customer);

                if (DataManager.DataManager.Instance.ValidateInputData <Model.Fare>(fare))
                {
                    user.Fares.Add(fare.Id);
                    DataManager.DataManager.Instance.AddNewEntity <Model.Location>(loc);
                    DataManager.DataManager.Instance.AddNewEntity <Model.Address>(addr);
                    DataManager.DataManager.Instance.AddNewEntity <Model.Fare>(fare);
                    DataManager.DataManager.Instance.UpdateEntity <Model.User>(user);
                    retVal = true;
                }
            }
            catch (Exception ex)
            {
                report = ex.Message;
            }
            return(retVal);
        }
Beispiel #2
0
        public bool UpdateDispatcherFare(long id, double locX, double locY, string addrStreet, int addrNumber, string addrCity, int addrPostalCode, double price, FareStatus status, out string report)
        {
            report = string.Empty;
            bool retVal = false;

            try
            {
                var fare = DataManager.DataManager.Instance.GetById <Model.Fare>(id);
                if (fare != null)
                {
                    fare.FareStatus = status;
                    fare.Amount     = price;
                    Model.Location fareFinishLocation = new Model.Location(locX, locY);
                    Model.Address  fareFinishAddress  = new Model.Address(addrStreet, addrNumber, addrCity, addrPostalCode);
                    fareFinishLocation.Address = fareFinishAddress.Id;
                    fare.FinishLocation        = fareFinishLocation.Id;
                    DataManager.DataManager.Instance.AddNewEntity <Model.Location>(fareFinishLocation);
                    DataManager.DataManager.Instance.AddNewEntity <Model.Address>(fareFinishAddress);
                    DataManager.DataManager.Instance.UpdateEntity <Model.Fare>(fare);
                    retVal = true;
                }
            }
            catch (Exception ex)
            {
                report = ex.Message;
                retVal = false;
            }
            return(retVal);
        }
        public bool UpdateDriverLocation(double locX, double locY, string addrStreet, int addrNumber, string addrCity, int addrPostalCode, long id, out string report)
        {
            bool retVal = false;

            report = string.Empty;
            try
            {
                var driver   = DataManager.DataManager.Instance.GetById <Model.Driver>(id);
                var location = DataManager.DataManager.Instance.GetRelatedEntity <Model.Driver, Model.Location>(id, "Location");
                if (location == null)
                {
                    Model.Location loc  = new Model.Location(locX, locY);
                    Model.Address  addr = new Model.Address(addrStreet, addrNumber, addrCity, addrPostalCode);
                    loc.Address     = addr.Id;
                    driver.Location = loc.Id;

                    DataManager.DataManager.Instance.AddNewEntity <Model.Location>(loc);
                    DataManager.DataManager.Instance.AddNewEntity <Model.Address>(addr);
                    DataManager.DataManager.Instance.UpdateEntity <Model.Driver>(driver);
                }
                else
                {
                    location.X = locX;
                    location.Y = locY;
                    var address = DataManager.DataManager.Instance.GetById <Model.Address>(location.Address);
                    if (address != null)
                    {
                        address.Street     = addrStreet;
                        address.Number     = addrNumber;
                        address.City       = addrCity;
                        address.PostalCode = addrPostalCode;
                        DataManager.DataManager.Instance.UpdateEntity <Model.Address>(address);
                    }
                    else
                    {
                        address          = new Model.Address(addrStreet, addrNumber, addrCity, addrPostalCode);
                        location.Address = address.Id;
                        DataManager.DataManager.Instance.AddNewEntity <Model.Address>(address);
                    }

                    DataManager.DataManager.Instance.UpdateEntity <Model.Location>(location);
                }
                retVal = true;
            }
            catch (Exception ex)
            {
                report = ex.Message;
                retVal = false;
            }
            return(retVal);
        }
Beispiel #4
0
        public bool CreateDriverFare(double locX, double locY, string addrStreet, int addrNumber, string addrCity, int addrPostalCode, long dispatherId, int vehicleType, DateTime date, long driverId, out string report)
        {
            report = string.Empty;
            bool retVal = false;

            try
            {
                Model.Location loc  = new Model.Location(locX, locY);
                Model.Address  addr = new Model.Address(addrStreet, addrNumber, addrCity, addrPostalCode);
                loc.Address = addr.Id;
                Model.Fare fare = new Model.Fare();
                fare.StartLocation = loc.Id;
                fare.Dispather     = dispatherId;
                if (vehicleType > 0)
                {
                    fare.DesiredVehicleType = (VehicleType)vehicleType;
                }
                fare.DateOfDrive = date;
                fare.Driver      = driverId;
                fare.FareStatus  = FareStatus.FORMED;

                var driver = DataManager.DataManager.Instance.GetById <Model.Driver>(driverId);

                if (DataManager.DataManager.Instance.ValidateInputData <Model.Fare>(fare))
                {
                    driver.Fares.Add(fare.Id);
                    driver.Busy = true;
                    DataManager.DataManager.Instance.AddNewEntity <Model.Location>(loc);
                    DataManager.DataManager.Instance.AddNewEntity <Model.Address>(addr);
                    DataManager.DataManager.Instance.AddNewEntity <Model.Fare>(fare);
                    DataManager.DataManager.Instance.UpdateEntity <Model.Driver>(driver);
                    retVal = true;
                }
            }
            catch (Exception ex)
            {
                report = ex.Message;
            }
            return(retVal);
        }