Exemplo n.º 1
0
        public int?RegisterUser(UserRegistration registration, LoggedInUser loggedInUser, List <ValidationMessage> validationMessages)
        {
            if (!CommonValidationHelper.ValidateLoggedInUser(loggedInUser, validationMessages))
            {
                return(null);
            }

            var station = new Station {
                Name = registration.StationName, StationCode = registration.StationCode, Address = registration.Address, MobileNumber = registration.MobileNumber
            };
            var stationId = _stationsRepository.AddStation(station, validationMessages);

            if (stationId != null)
            {
                var userDetails = new UserDetails {
                    Username = registration.UserName, Password = registration.Password, Email = registration.Email, IsAdmin = registration.IsAdmin
                };
                var userId   = _userRepository.AddUser(userDetails, validationMessages);
                var supplier = new Supplier {
                    FirstName = registration.FirstName, LastName = registration.LastName, Address = registration.Address, MobileNumber = registration.MobileNumber, StationId = stationId ?? 0, UserId = userId
                };
                var supplierId = _suppliersRepository.AddSupplier(supplier, validationMessages);
                return(userId);
            }

            return(null);
        }
Exemplo n.º 2
0
        public int?UpsertSupplier(Supplier supplier, LoggedInUser loggedInUser, List <ValidationMessage> validationMessages)
        {
            if (!CommonValidationHelper.ValidateLoggedInUser(loggedInUser, validationMessages))
            {
                return(null);
            }

            supplier.StationId = loggedInUser.StationId ?? 0;
            var result = _suppliersRepository.AddSupplier(supplier, validationMessages);

            return(result);
        }
        /// <summary>
        /// Adds a Supplier
        /// Level: Logic
        /// </summary>
        /// <param name="Supplier">The Supplier Name</param>
        /// <param name="Email">The Supplier Email</param>
        /// <param name="Postcode">The Postcode</param>
        /// <param name="StreetAddress">The Street Address</param>
        /// <param name="Town">The Town</param>
        /// <param name="Country">The Country</param>
        public void AddSupplier(string Supplier, string Email, string Postcode, string StreetAddress,
                                string Town, string Country)
        {
            try
            {
                SuppliersRepository myRepository = new SuppliersRepository();

                Supplier mySupplier = new Supplier();

                mySupplier.Supplier1     = Supplier;
                mySupplier.Email         = Email;
                mySupplier.Postcode      = Postcode;
                mySupplier.StreetAddress = StreetAddress;

                Town myTown = myRepository.RetrieveTown(Town, Country);

                //If Town Exists
                if (myTown != null)
                {
                    //Assigning Existent Town to Supplier
                    mySupplier.Town = myTown;
                }
                else
                {
                    //Instanciating New Town
                    myTown         = new Town();
                    myTown.Town1   = Town;
                    myTown.Country = myRepository.RetrieveCountry(Country);

                    //Assigning New Town to Supplier
                    mySupplier.Town = myTown;
                }

                myRepository.AddSupplier(mySupplier);
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }