using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.Caching; using Ease.CoreV35.Model; namespace Payroll.BO { #region Vendor [Serializable] public class Vendor : BasicBaseObject { #region Cache Store private static Cache _cache = new Cache(typeof(Vendor)); #endregion #region Constructor public Vendor() { _sName = string.Empty; _sAddress = string.Empty; _dBalance = 0.0; _sMobile = string.Empty; _sTelephone = string.Empty; _sEmailAddress = string.Empty; _sContactPerson = string.Empty; } #endregion #region Input validator public string[] InputValidator() { string[] sErrorString = new string[2]; if (this.Name == "") { sErrorString[0] = "Description can not be empty"; sErrorString[1] = "Description"; return sErrorString; } sErrorString = null; return sErrorString; } #endregion #region Properties #region Name private string _sName; public string Name { get { return _sName; } set { _sName = value; } } #endregion #region VendorType private EnumVendorType _eVendorType; public EnumVendorType VendorType { get { return _eVendorType; } set { _eVendorType = value; } } #endregion #region Balance private double _dBalance; public double Balance { get { return _dBalance; } set { _dBalance = value; } } #endregion #region Mobile private string _sMobile; public string Mobile { get { return _sMobile; } set { _sMobile = value; } } #endregion #region Telephone private string _sTelephone; public string Telephone { get { return _sTelephone; } set { _sTelephone = value; } } #endregion #region EmailAddress private string _sEmailAddress; public string EmailAddress { get { return _sEmailAddress; } set { _sEmailAddress = value; } } #endregion #region ContactPerson private string _sContactPerson; public string ContactPerson { get { return _sContactPerson; } set { _sContactPerson = value; } } #endregion #region Address private string _sAddress; public string Address { get { return _sAddress; } set { _sAddress = value; } } #endregion #region Service Factory internal static IVendorService Service { get { return Services.Factory.CreateService(typeof(IVendorService)); } } #endregion #endregion #region Functions public static string GetVendorTypeForCreateUI() { var values = Enum.GetValues(typeof(EnumVendorType)) .Cast() .Select(e => new { Text = e.ToString(), Numbr = (int)e }); String enumList = string.Empty; foreach (var value in values) { enumList = enumList + value.Text + "=" + (value.Numbr) + "|"; } enumList = enumList.Remove(enumList.Length - 1, 1); return enumList; } public static Vendor Get(ID vendorId) { Vendor oVendor = null; #region Cache Header oVendor = (Vendor)_cache["Get", vendorId]; if (oVendor != null) return oVendor; #endregion oVendor = Vendor.Service.Get(vendorId); #region Cache Footer _cache.Add(oVendor, "Get", vendorId); #endregion return oVendor; } public ID Save() { this.SetAuditTrailProperties(); return Vendor.Service.Save(this); } public void Delete(ID id) { Vendor.Service.Delete(id); } #endregion #region Collection Functions public static ObjectsTemplate Get() { #region Cache Header ObjectsTemplate vendors = _cache["Get"] as ObjectsTemplate; if (vendors != null) return vendors; #endregion vendors = Vendor.Service.Get(); #region Cache Footer _cache.Add(vendors, "Get"); #endregion return vendors; } public static ObjectsTemplate Get(EnumVendorType vendorType) { #region Cache Header ObjectsTemplate vendors = _cache["Get", vendorType] as ObjectsTemplate; if (vendors != null) return vendors; #endregion try { vendors = Vendor.Service.Get(vendorType); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(vendors, "Get", vendorType); #endregion return vendors; } public static ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate vendors = _cache["Get", status] as ObjectsTemplate; if (vendors != null) return vendors; #endregion try { vendors = Vendor.Service.Get(status); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(vendors, "Get", status); #endregion return vendors; } public static ObjectsTemplate GetByName(string subStr) { #region Cache Header ObjectsTemplate vendors = _cache["Get", subStr] as ObjectsTemplate; if (vendors != null) return vendors; #endregion try { vendors = Vendor.Service.Get(subStr); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(vendors, "Get", subStr); #endregion return vendors; } #endregion } #endregion #region IVendor Service public interface IVendorService { Vendor Get(ID id); ObjectsTemplate Get(); ObjectsTemplate Get(EnumVendorType vendorType); ID Save(Vendor oVendor); void Delete(ID id); ObjectsTemplate Get(EnumStatus status); ObjectsTemplate Get(string subStr); } #endregion }