Exemple #1
0
        /// <summary>
        /// Updates Employee information
        /// </summary>
        /// <param name="employee"></param>
        /// <returns></returns>
        public bool UpdateEmployeeByID(Employee employee)
        {
            bool result = false;

            //Set Hire Date - control must be created in presentation layer
            employee.HireDate = DateTime.Now;

            //Handle Empty SSN Issue
            employee.SSNo = employee.SSNo != null ? employee.SSNo : String.Empty;

            //Handle Empty Pic Url issue
            employee.PicUrl = employee.PicUrl != null ? employee.PicUrl : String.Empty;

            //User isBlocked :: False
            employee.isBlocked = false;

            //Update Employee Details
            result = EmployeeAccessor.UpdateEmployeeByID(employee);

            //Update Employee Address
            int count = 0;

            try
            {
                if (employee.Address != null)
                {
                    foreach (var addressElement in employee.Address)
                    {
                        if (addressElement.UserAddressId != 0) // Update Employee Address
                        {
                            count += EmployeeAccessor.UpdateAddressByUserID(employee.UserId, addressElement);
                        }
                        else // Create New Address
                        {
                            count += EmployeeAccessor.CreateAddressByUserID(employee.UserId, addressElement);
                        }
                    }

                    //Check if write was successful
                    if (employee.UserId != 0 && count == employee.Address.Count)
                    {
                        result = true;
                    }

                    else
                    {
                        result = false;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            //Perform update for addresses
            return(result);
        }
Exemple #2
0
        // Employee CRUD

        /// <summary>
        /// Create new Employee
        /// </summary>
        /// <param name="employee">Employee Object</param>
        /// <returns>Return Confirmation Result</returns>
        public bool CreateEmployee(Employee employee)
        {
            bool result = false;

            //Set Password
            var userEncode = new UserManager();

            employee.PasswordHash = userEncode.HashSHA256(employee.Username.ToUpper());

            //Set Hire Date - control must be created in presentation layer
            employee.HireDate = DateTime.Now;

            //Handle Empty SSN Issue
            employee.SSNo = employee.SSNo != null ? employee.SSNo : String.Empty;

            //Handle Empty Pic Url issue
            employee.PicUrl = employee.PicUrl != null ? employee.PicUrl : String.Empty;

            //User isBlocked :: False
            employee.isBlocked = false;

            //Write Employee and Get new UserId
            employee.UserId = EmployeeAccessor.CreateEmployee(employee);

            // Write Addresses if not null
            int count = 0;

            if (employee.Address != null)
            {
                foreach (var addressElement in employee.Address)
                {
                    count += EmployeeAccessor.CreateAddressByUserID(employee.UserId, addressElement);
                }

                if (employee.UserId != 0 && count == employee.Address.Count)
                {
                    result = true;
                }

                return(result);
            }

            // Check for write succcess if address is null
            if (employee.UserId != 0)
            {
                result = true;
            }

            return(result);
        }
        public void CreateAddressByUserID()
        {
            Address ad     = new Address();
            int     userId = 10003;

            List <string> addresslines = new List <string>();

            addresslines.Add("St Louis St");
            addresslines.Add("Block C");
            addresslines.Add("Apt J");

            ad.AddressLines  = addresslines;
            ad.City          = "Dubuque";
            ad.StateID       = 45;
            ad.Zip           = "52334";
            ad.CountryID     = 45;
            ad.AddressTypeId = 3;

            int a = EmployeeAccessor.CreateAddressByUserID(userId, ad);

            Assert.AreEqual(1, a);
        }