LINQ INSERT UPDATE DELETE OPRATION EXAMPLE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAccessLayer.LINQ.Tables
{
    public class AccountTypes
    {
        DataAccessLayer.IxstaySolutionSuiteDataContext dc;
        public AccountTypes()
        {
            dc = new DataAccessLayer.IxstaySolutionSuiteDataContext(Config.SQLConnectionString);
        }

        public IQueryable getAccountTypes
        {
            get
            {
                var query = dc.AccountTypes
                    .Select(c => c);

                return query;

            }
        }
        public bool insertAccountTypes(Entity.AccountTypes entity)
        {
            bool retVal = false;
            DataAccessLayer.AccountType oAccountType=new DataAccessLayer.AccountType
       
            {
                //iAccountTypeID=entity.iAccountTypeID,
                iHotelID = entity.iHotelID,
                bActive = entity.bActive ,
                bDelete =  entity.bDelete,
                dtmEntryDate = DateTime.Now,
                dtmUpdateDate = DateTime.Now,
                vchAccountType=entity.vchAccountType
             };

            dc.AccountTypes.InsertOnSubmit(oAccountType);
            try
            {
            dc.SubmitChanges();

            return true;
            }
            catch (Exception exp)
            {
                Utility.ShowException(exp);
                retVal = false;
            }

            return retVal;
        }
        public bool updateAccountTypes(int iAccountTypeID, Entity.AccountTypes entity)
        {
            bool retVal = false;

            var updateQuery = dc.AccountTypes
                .Where(c => c.iAccountTypeID == iAccountTypeID)
                .Select(c => c);

            foreach (var c in updateQuery)
            {
                c.iHotelID = entity.iHotelID;
                if (string.IsNullOrEmpty(entity.vchAccountType.ToString())) c.vchAccountType = entity.vchAccountType;
               

                 c.bActive = entity.bActive;
                c.bDelete = entity.bDelete;

                c.dtmEntryDate = DateTime.Now;
                c.dtmUpdateDate = DateTime.Now;
            }

            try
            {
                dc.SubmitChanges();
                retVal = true;
            }
            catch (Exception exp)
            {
                Utility.ShowException(exp);
                retVal = false;
            }

            return retVal;
        }

        public bool deleteAccountTypes(int iAccountTypeID, int iHotelID)
        {
            bool retVal = false;

            var deleteQuery = dc.AccountTypes
                .Where(c => c.iAccountTypeID == iAccountTypeID && c.iHotelID == iHotelID)
                .Select(c => c);

            foreach (var c in deleteQuery)
            {
                dc.AccountTypes.DeleteOnSubmit(c);
            }

            try
            {
                dc.SubmitChanges();
                retVal = true;
            }
            catch (Exception exp)
            {
                Utility.ShowException(exp);
                retVal = false;
            }

            return retVal;
        }
    }
}

Comments

Contact Form

Send