/// <summary>
        /// Initializes a new instance of the <see cref="T:UserDetails"/> class.
        /// </summary>
        /// <param name="membershipUser">The membership user.</param>
        /// <param name="getProfile">if set to <c>true</c> [get profile].</param>
        public UserDetails(MembershipUser membershipUser, bool getProfile)
        {
            if (membershipUser != null)
            {
                UserName         = membershipUser.UserName;
                Email            = membershipUser.Email;
                LastActivityDate = membershipUser.LastActivityDate.ToShortDateString();

                if (getProfile)
                {
                    ProfileCommon p       = new ProfileCommon();
                    ProfileCommon profile = p.GetProfile(membershipUser.UserName);


                    if (profile != null)
                    {
                        OpCoId          = profile.OpCoId;
                        OpCoCode        = profile.OpCoCode;
                        RegionId        = profile.RegionId;
                        RegionCode      = profile.RegionCode;
                        WarehouseId     = profile.WarehouseId;
                        SalesLocationId = profile.SalesLocationId;
                        SalesLocation   = SalesLocationController.GetLocation(salesLocationId, false);
                        OpCo            = OpcoController.GetOpCo(OpCoId, false);
                        Warehouse       = WarehouseController.GetWarehouse(WarehouseId);
                        Region          = OptrakRegionController.GetRegion(RegionId);
                    }
                }
            }
        }
        internal bool DeleteItem(int Id)
        {
            SalesLocation salesLocation = new SalesLocation();

            salesLocation.Id = Id;
            return(SalesLocationController.DeleteLocation(salesLocation));
        }
Exemple #3
0
        /// <summary>
        /// Saves the specified SalesLocation to the underlying data store via the configured DataProvider.
        /// If the primary key (ID) of the supplied SalesLocation is Null, a new row is added to the underlying data store and a new primary key (ID) automatically generated.  If the primary key (ID) of the supplied SalesLocation has been specified, the existing row in the data store is updated if it has not already been altered.
        /// The primary key (ID) of the created or altered SalesLocation is returned to the caller.  If an error occurs, an exception is thrown and no updates made to the data store.
        /// For concurrency errors (the data has changed in-between load and save by an external system or user), a concurrency exception is thrown.
        /// </summary>
        /// <param name="salesLocation">The salesLocation.</param>
        /// <returns></returns>
        public static int SaveLocation(SalesLocation salesLocation)
        {
            try
            {
                if (salesLocation.IsValid)
                {
                    salesLocation.OpCo = OpcoController.GetOpCo(salesLocation.OpCoId, true);
                    // Save entity
                    salesLocation.Id = DataAccessProvider.Instance().SaveLocation(salesLocation);
                    if (salesLocation.Id != -1)
                    {
                        FrameworkController.GetChecksum(salesLocation);
                        CacheManager.Add(salesLocation, salesLocation.OpCo != null);
                    }
                }
                else
                {
                    // Entity is not valid
                    throw new InValidBusinessObjectException(salesLocation);
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }

            // Done
            return(salesLocation.Id);
        }
Exemple #4
0
        /// <summary>
        /// Retrieves a single SalesLocation entry from the underlying data store via the configured DataProvider for the supplied SalesLocation ID.
        /// An instance of a SalesLocation is returned to the caller or Null if no SalesLocation record is found.  If an error occurs, an exception is thrown.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="fullyPopulate">if set to <c>true</c> [fullyPopulate].</param>
        /// <returns></returns>
        public static SalesLocation GetLocation(string code, bool fullyPopulate)
        {
            SalesLocation salesLocation = new SalesLocation();

            try
            {
                salesLocation = CacheManager.Get <SalesLocation>(code, fullyPopulate);
                if (salesLocation == null)
                {
                    salesLocation = CBO <SalesLocation> .FillObject(DataAccessProvider.Instance().GetLocation(code), FullyPopulate, fullyPopulate);

                    if (salesLocation != null)
                    {
                        CacheManager.Add(salesLocation, salesLocation.Location, fullyPopulate);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }
            return(salesLocation);
        }
 public void DeleteItem()
 {
     using (TransactionScope scope = new TransactionScope())
     {
         SalesLocation salesLocation = PopulateNewItem();
         int           id            = SaveItem(salesLocation);
         Assert.IsTrue(DeleteItem(id));
     }
 }
        public void SaveLocationTestConstraint()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                SalesLocation salesLocation = PopulateNewItem();

                SaveItem(salesLocation);

                SaveItem(salesLocation);
            }
        }
        public void GetItem()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                SalesLocation salesLocation = PopulateNewItem();
                int           id            = SaveItem(salesLocation);


                Assert.IsNotNull(GetItem(id, true));
            }
        }
Exemple #8
0
 /// <summary>
 /// Fully populates the SalesLocation
 /// </summary>
 /// <param name="salesLocation">The salesLocation.</param>
 /// <param name="dataReader">The data reader.</param>
 /// <param name="fullyPopulate">if set to <c>true</c> [fullyPopulate].</param>
 private static void FullyPopulate(SalesLocation salesLocation, IDataReader dataReader, bool fullyPopulate)
 {
     if (fullyPopulate && salesLocation != null)
     {
         if (allOpCos != null && allOpCos.Count > 0)
         {
             salesLocation.OpCo = allOpCos.Find(delegate(OpCo obj) { return(obj.Id == salesLocation.OpCoId); });
         }
         else
         {
             salesLocation.OpCo = OpcoController.GetOpCo(salesLocation.OpCoId, true);
         }
     }
 }
        internal SalesLocation PopulateNewItem()
        {
            SalesLocation salesLocation = new SalesLocation();

            salesLocation.TelephoneNumber = "TelephoneNumber";
            salesLocation.Location        = "Location";

            salesLocation.OpCo    = OpcoTests.PopulateNewItem();
            salesLocation.OpCo.Id = OpcoController.SaveOpCo(salesLocation.OpCo);
            salesLocation.OpCoId  = salesLocation.OpCo.Id;

            salesLocation.Description = "Test";
            salesLocation.UpdatedBy   = "test";
            return(salesLocation);
        }
        public void UpdateItem()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                SalesLocation item = PopulateNewItem();
                item.Description = "Original";
                item.Id          = SaveItem(item);


                item = GetItem(item.Id, true);
                //change a value
                item.Description = "Updated";
                SaveItem(item);
                item = GetItem(item.Id, true);
                Assert.IsTrue(item.Description == "Updated");
            }
        }
        public void GetItems()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                SalesLocation salesLocation = PopulateNewItem();
                int           id            = SaveItem(salesLocation);

                //retrieve all sales locations and the one we saved should return at least
                List <SalesLocation> salesLocations = SalesLocationController.GetLocations(true);
                //so the count should be >0
                Assert.IsTrue(salesLocations.Count > 0);
                //check for our new id
                Assert.IsTrue(salesLocations.Find(delegate(SalesLocation currentItem)
                {
                    return(currentItem.Id == id);
                }) != null);
            }
        }
        public void ConcurrencyTest()
        {
            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    SalesLocation item = PopulateNewItem();
                    item.Id = SaveItem(item);
                    //change a value
                    item.Description = "Updated";

                    SaveItem(item);
                }
                catch (DiscoveryException e)
                {
                    Assert.IsInstanceOfType(typeof(ConcurrencyException), e.InnerException);
                    throw e;
                }
            }
        }
Exemple #13
0
        /// <summary>
        /// Deletes the specified SalesLocation record from the underlying data store via the configured DataProvider.
        /// If the specified SalesLocation is deleted true is returned otherwise false.  If an error occurs, an exception is thrown.
        /// </summary>
        /// <param name="location">The Sales Location to delete.</param>
        /// <returns></returns>
        public static bool DeleteLocation(SalesLocation location)
        {
            bool success = false;

            try
            {
                if (location != null)
                {
                    success = DataAccessProvider.Instance().DeleteLocation(location.Id);;
                    if (success)
                    {
                        CacheManager.Remove(location);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }
            return(success);
        }
 internal int SaveItem(SalesLocation salesLocation)
 {
     return(SalesLocationController.SaveLocation(salesLocation));
 }