예제 #1
0
        /// <summary>
        /// Called when the user wants to update a sale 
        /// </summary>
        /// <param name="sender">event owner</param>
        /// <param name="e">Event args</param>
        private void View_Update(object sender, UpdateInputArgs<Sale> e)
        {
            if (!OpenSession())
                return;

            // Ensure network state hasn't changed!
            // If it has we cannot ensure a safe update so we cannot continue the process
            if ((e.IsLocal && SessionContext.IsLocal()) ||
                (e.IsLocal == false && SessionContext.IsLocal() == false))
            {

                var isDirty = false;
                if (e.Entity == null)
                {
                    OperationFailed(new Exception("No object available!"),
                        "Object to update was missing from the collection!");
                    return;
                }

                if (_view.StoreId != 0)
                {
                    e.Entity.StoreId = _view.StoreId;
                    isDirty = true;
                }

                if (_view.ProductId != 0)
                {
                    e.Entity.ProductId = _view.ProductId;
                    isDirty = true;
                }

                if (_view.Timestamp.HasValue)
                {
                    e.Entity.SaleTime = _view.Timestamp.Value;
                    isDirty = true;
                }

                // No properties were changed inform the user
                // and do not continue with the update
                if (isDirty == false)
                {
                    UpdateStatus("Record not updated, no values changed!");
                    return;
                }

                try
                {
                    // Update the record
                    _saleRepository.Save(e.Entity);
                    _saleRepository.Commit();

                    UpdateStatus("\nRecord updated successfully!");
                }
                catch (Exception ex)
                {
                    OperationFailed(ex, "Could not update record\n");
                }
            }
            else
            {
                OperationFailed(new Exception("Network state changed mid update!"), "Could not update record!");
            }
        }
        /// <summary>
        /// Called when the user wants to update a store
        /// </summary>
        /// <param name="sender">Event owner</param>
        /// <param name="e">Event args</param>
        private void View_Update(object sender, UpdateInputArgs<Store> e)
        {
            if (!OpenSession())
                return;

            // Ensure network state hasn't changed!
            // If it has we cannot ensure a safe update so we cannot continue the process
            if ((e.IsLocal && SessionContext.IsLocal()) ||
                (e.IsLocal == false && SessionContext.IsLocal() == false))
            {
                // We should have at least 1 record
                // inform the user and do not update
                if (e.Entity == null)
                {
                    OperationFailed(new Exception("No object available!"),
                        "Object to update was missing from the collection!");
                    return;
                }

                if (!string.IsNullOrEmpty(_view.StoreName))
                {
                    e.Entity.StoreName = _view.StoreName;
                }
                else
                {
                    // Nothing changed inform the user
                    UpdateStatus("Record not updated, value was not changed!");
                    return;
                }

                try
                {
                    // Update record in DB
                    _storeRepository.Save(e.Entity);
                    _storeRepository.Commit();

                    UpdateStatus("Record updated successfully!");
                }
                catch (Exception ex)
                {
                    OperationFailed(ex, "Could not update record!");
                }
            }
            else
            {
                OperationFailed(new Exception("Network state changed mid update!"), "Could not update record!");
            }
        }
        /// <summary>
        /// Called when a user wants to update a entity
        /// </summary>
        /// <param name="sender">Event owner</param>
        /// <param name="e">Event args</param>
        private void View_Update(object sender, UpdateInputArgs<Product> e)
        {
            if (!OpenSession())
                return;

            // Ensure network state hasn't changed!
            // If it has we cannot ensure a safe update so we cannot continue the process
            if ((e.IsLocal && SessionContext.IsLocal()) ||
                (e.IsLocal == false && SessionContext.IsLocal() == false))
            {

                var isDirty = false;

                // We should have at least 1 object
                // if not inform the user and prevent the update
                if (e.Entity == null)
                {
                    OperationFailed(new Exception("No object available!"),
                        "Object to update was missing from the collection!");
                    return;
                }

                if (!string.IsNullOrEmpty(_view.Name))
                {
                    e.Entity.Prod_Name = _view.Name;
                    isDirty = true;
                }

                if (_view.Price.HasValue)
                {
                    e.Entity.Price = _view.Price.Value;
                    isDirty = true;
                }

                // No properties were changed inform the user
                // we don't need to update the entity
                if (isDirty == false)
                {
                    UpdateStatus("Record not updated, no values changed!");
                    return;
                }

                try
                {
                    // Update the entity in the DB
                    _productRepository.Save(e.Entity);
                    _productRepository.Commit();

                    UpdateStatus("\nRecord updated successfully!");
                }
                catch (Exception ex)
                {
                    OperationFailed(ex, "Could not update product");
                }
            }
            else
            {
                OperationFailed(new Exception("Network state changed mid update!"), "Could not update record!");
            }
        }