CartOffer.cs :  » Content-Management-Systems-CMS » mojoPortal » WebStore » Business » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Content Management Systems CMS » mojoPortal 
mojoPortal » WebStore » Business » CartOffer.cs
/// Author:          Joe Audette
/// Created:        2007-03-14
/// Last Modified:      2009-02-01
/// 
/// The use and distribution terms for this software are covered by the 
/// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)  
/// which can be found in the file CPL.TXT at the root of this distribution.
/// By using this software in any fashion, you are agreeing to be bound by 
/// the terms of this license.
///
/// You must not remove this notice, or any other, from this software.

using System;
using System.Collections.Generic;
using System.Data;
using WebStore.Data;

namespace WebStore.Business{
    /// <summary>
    /// Represents an offer in the cart
    /// </summary>
    [Serializable()]
    public class CartOffer
    {

        #region Constructors

        public CartOffer()
        { }

        #endregion

        #region Private Properties

        private string name = string.Empty;
        private Guid itemGuid = Guid.Empty;
        private Guid cartGuid = Guid.Empty;
        private Guid offerGuid = Guid.Empty;
        //private Guid priceGuid = Guid.Empty;
        //private Guid currencyGuid = Guid.Empty;
        private Guid taxClassGuid = Guid.Empty;
        private decimal offerPrice = 0;
        private decimal tax = 0;
        private DateTime addedToCart = DateTime.UtcNow;
        private int quantity = 1;
        private bool isDonation = false;

        #endregion

        #region Public Properties

        public string Name
        {
            get { return name; }
            
        }

        public Guid ItemGuid
        {
            get { return itemGuid; }
            set { itemGuid = value; } //needs to get writeable to apply guid to current cart
        }
        public Guid CartGuid
        {
            get { return cartGuid; }
            set { cartGuid = value; }
        }
        public Guid OfferGuid
        {
            get { return offerGuid; }
            set { offerGuid = value; }
        }
        //public Guid PriceGuid
        //{
        //    get { return priceGuid; }
        //    set { priceGuid = value; }
        //}
        //public Guid CurrencyGuid
        //{
        //    get { return currencyGuid; }
        //    set { currencyGuid = value; }
        //}
        public Guid TaxClassGuid
        {
            get { return taxClassGuid; }
            set { taxClassGuid = value; }
        }
        public decimal OfferPrice
        {
            get { return offerPrice; }
            set { offerPrice = value; }
        }
        public decimal Tax
        {
            get { return tax; }
            set { tax = value; }
        }
        public DateTime AddedToCart
        {
            get { return addedToCart; }
            set { addedToCart = value; }
        }
        public int Quantity
        {
            get { return quantity; }
            set { quantity = value; }
        }

        public bool IsDonation
        {
            get { return isDonation; }
            set { isDonation = value; }
        }

        #endregion


        #region Private Methods

        /// <summary>
        /// Persists a new instance of CartOffer. Returns true on success.
        /// </summary>
        /// <returns></returns>
        private bool Create()
        {
            this.itemGuid = Guid.NewGuid();

            int rowsAffected = DBCartOffer.Add(
                this.itemGuid,
                this.cartGuid,
                this.offerGuid,
                this.taxClassGuid,
                this.offerPrice,
                this.addedToCart,
                this.quantity,
                this.tax,
                this.isDonation);

            return (rowsAffected > 0);

        }


        /// <summary>
        /// Updates this instance of CartOffer. Returns true on success.
        /// </summary>
        /// <returns>bool</returns>
        private bool Update()
        {

            return DBCartOffer.Update(
                this.itemGuid,
                this.offerGuid,
                this.taxClassGuid,
                this.offerPrice,
                this.addedToCart,
                this.quantity,
                this.tax,
                this.isDonation);

        }


        #endregion


        /// <summary>
        /// Saves this instance of CartOffer. Returns true on success.
        /// </summary>
        /// <returns>bool</returns>
        public bool Save()
        {
            if (this.itemGuid != Guid.Empty)
            {
                return Update();
            }
            else
            {
                return Create();
            }
        }


        public static List<CartOffer> GetByCart(Guid cartGuid)
        {
            IDataReader reader = DBCartOffer.GetByCart(cartGuid);
            return LoadListFromReader(reader);


        }

        private static List<CartOffer> LoadListFromReader(IDataReader reader)
        {
            List<CartOffer> cartOfferList = new List<CartOffer>();
            try
            {
                while (reader.Read())
                {
                    CartOffer cartOffer = new CartOffer();
                    cartOffer.itemGuid = new Guid(reader["ItemGuid"].ToString());
                    cartOffer.cartGuid = new Guid(reader["CartGuid"].ToString());
                    cartOffer.offerGuid = new Guid(reader["OfferGuid"].ToString());

                    cartOffer.taxClassGuid = new Guid(reader["TaxClassGuid"].ToString());
                    cartOffer.offerPrice = Convert.ToDecimal(reader["OfferPrice"]);
                    cartOffer.addedToCart = Convert.ToDateTime(reader["AddedToCart"]);
                    cartOffer.quantity = Convert.ToInt32(reader["Quantity"]);
                    cartOffer.name = reader["Name"].ToString();
                    if (reader["Tax"] != DBNull.Value)
                    {
                        cartOffer.tax = Convert.ToDecimal(reader["Tax"]);
                    }

                    cartOffer.isDonation = Convert.ToBoolean(reader["IsDonation"]);

                    cartOfferList.Add(cartOffer);

                }
            }
            finally
            {
                reader.Close();
            }

            return cartOfferList;

        }

        public static bool DeleteByCart(Guid cartGuid)
        {
            return DBCartOffer.DeleteByCart(cartGuid);
        }

        public static bool DeleteAnonymousByStore(Guid storeGuid, DateTime olderThan)
        {
            return DBCartOffer.DeleteAnonymousByStore(storeGuid, olderThan);
        }

        public static bool DeleteByStore(Guid storeGuid, DateTime olderThan)
        {
            return DBCartOffer.DeleteByStore(storeGuid, olderThan);
        }

    }

}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.