Exemplo n.º 1
0
        //Add new record
        public static int AddRecord(etblPropertyTaxMap eobj)
        {
            int    PropTaxId = 0;
            string Status    = "";
            int    retval    = 0;
            int    count     = 0;

            using (OneFineRateEntities db = new OneFineRateEntities())
            {
                try
                {
                    bool checkExists = false;
                    //checkExists = CheckTaxRecordExists(eobj);
                    if (eobj.iRoomId != null)
                    {
                        checkExists = db.tblPropertyTaxMaps.Any(
                            p => p.iPropId == eobj.iPropId &&
                            (p.iRoomId == eobj.iRoomId || p.iRoomId == null) &&
                            p.cStatus == "A" &&
                            (((p.dtStayFrom <= eobj.dtStayFrom && p.dtStayTo >= eobj.dtStayFrom) || (p.dtStayFrom <= eobj.dtStayTo && p.dtStayTo >= eobj.dtStayTo)) ||
                             ((eobj.dtStayFrom <= p.dtStayFrom && eobj.dtStayTo >= p.dtStayFrom) || (eobj.dtStayFrom <= p.dtStayTo && eobj.dtStayTo >= p.dtStayTo)))
                            );
                    }
                    else
                    {
                        checkExists = db.tblPropertyTaxMaps.Any(
                            p => p.iPropId == eobj.iPropId
                            //&& ((p.iRoomId != null && p.cStatus != "A") || (p.iRoomId == null))
                            && (((p.iRoomId != null) && p.cStatus == "A") || ((p.iRoomId == null)))

                            && (((p.dtStayFrom <= eobj.dtStayFrom && p.dtStayTo >= eobj.dtStayFrom) || (p.dtStayFrom <= eobj.dtStayTo && p.dtStayTo >= eobj.dtStayTo)) ||
                                ((eobj.dtStayFrom <= p.dtStayFrom && eobj.dtStayTo >= p.dtStayFrom) || (eobj.dtStayFrom <= p.dtStayTo && eobj.dtStayTo >= p.dtStayTo)))
                            );
                    }

                    if (checkExists != true)
                    {
                        OneFineRate.tblPropertyTaxMap dbuser = (OneFineRate.tblPropertyTaxMap)OneFineRateAppUtil.clsUtils.ConvertToObject(eobj, new OneFineRate.tblPropertyTaxMap());
                        db.tblPropertyTaxMaps.Add(dbuser);
                        db.SaveChanges();
                        PropTaxId = dbuser.iPropTaxId;
                        Status    = dbuser.cStatus;

                        OneFineRate.tblPropertyTaxesMap dbnew = (OneFineRate.tblPropertyTaxesMap)OneFineRateAppUtil.clsUtils.ConvertToObject(eobj, new OneFineRate.tblPropertyTaxesMap());
                        //Add mapings
                        if (eobj.PropertyTaxesList != null)
                        {
                            db.tblPropertyTaxesMaps.AddRange(eobj.PropertyTaxesList.Select(x => new tblPropertyTaxesMap()
                            {
                                iPropTaxId   = PropTaxId,
                                iTaxId       = x.iTaxId,
                                bIsPercent   = x.bIsPercent,
                                dValue       = x.dValue,
                                dtActionDate = x.dtActionDate,
                                iActionBy    = x.iActionBy
                            }).ToList());
                        }

                        db.SaveChanges();

                        #region Propperty Room Tax List

                        List <PropertyRoomTaxList> LPRPC = new List <PropertyRoomTaxList>();

                        if (eobj.iRoomId != null)
                        {
                            DateTime CurrentDate = (DateTime)eobj.dtStayFrom;
                            while (CurrentDate <= eobj.dtStayTo)
                            {
                                PropertyRoomTaxList PRPC = new PropertyRoomTaxList();
                                PRPC.dtStay       = CurrentDate;
                                PRPC.iPropTaxId   = PropTaxId;
                                PRPC.iPropId      = eobj.iPropId;
                                PRPC.iRoomId      = (long)eobj.iRoomId;
                                PRPC.iActionBy    = (int)eobj.iActionBy;
                                PRPC.dtActionDate = DateTime.Now;
                                PRPC.cStatus      = Status;

                                LPRPC.Add(PRPC);
                                CurrentDate = CurrentDate.AddDays(1);
                            }
                        }
                        else
                        {
                            List <PNames> objRoomList = new List <PNames>();
                            objRoomList = BL_tblPropertyRoomMap.GetAllPropertyTypes(eobj.iPropId);
                            foreach (var item in objRoomList)
                            {
                                DateTime CurrentDate = (DateTime)eobj.dtStayFrom;
                                while (CurrentDate <= eobj.dtStayTo)
                                {
                                    PropertyRoomTaxList PRPC = new PropertyRoomTaxList();
                                    PRPC.dtStay       = CurrentDate;
                                    PRPC.iPropTaxId   = PropTaxId;
                                    PRPC.iPropId      = eobj.iPropId;
                                    PRPC.iRoomId      = Convert.ToInt64(item.Id);
                                    PRPC.iActionBy    = (int)eobj.iActionBy;
                                    PRPC.dtActionDate = DateTime.Now;
                                    PRPC.cStatus      = Status;


                                    LPRPC.Add(PRPC);
                                    CurrentDate = CurrentDate.AddDays(1);
                                }
                            }
                        }

                        if (LPRPC != null)
                        {
                            db.tblPropertyRoomTaxMaps.AddRange(LPRPC.Select(m => new tblPropertyRoomTaxMap()
                            {
                                dtStay       = m.dtStay,
                                iPropTaxId   = m.iPropTaxId,
                                iPropId      = m.iPropId,
                                iRoomId      = (long)m.iRoomId,
                                dtActionDate = m.dtActionDate,
                                iActionBy    = m.iActionBy,
                                cStatus      = m.cStatus
                            }));
                        }

                        db.SaveChanges();
                        #endregion

                        retval = 1;
                    }
                    else
                    {
                        retval = 2;
                    }
                }

                catch (Exception)
                {
                    throw;
                }
            }
            return(retval);
        }
Exemplo n.º 2
0
        //Update a record
        public static int UpdateRecord(etblPropertyTaxMap eobj)
        {
            int retval = 0;

            using (OneFineRateEntities db = new OneFineRateEntities())
            {
                try
                {
                    var dbobjRoomId = db.tblPropertyTaxMaps.SingleOrDefault(u => u.iPropId == eobj.iPropId && u.iPropTaxId == eobj.iPropTaxId);
                    eobj.iRoomId = dbobjRoomId.iRoomId;

                    bool checkExists = false;

                    if (dbobjRoomId.iRoomId != null)
                    {
                        checkExists = db.tblPropertyTaxMaps.Any(
                            p => p.iPropId == eobj.iPropId &&
                            (p.iRoomId == eobj.iRoomId || p.iRoomId == null) &&
                            p.cStatus == "A" &&
                            p.iPropTaxId != eobj.iPropTaxId
                            // && p.iRoomId == null
                            // && p.cStatus == "A"
                            && (((p.dtStayFrom <= eobj.dtStayFrom && p.dtStayTo >= eobj.dtStayFrom) || (p.dtStayFrom <= eobj.dtStayTo && p.dtStayTo >= eobj.dtStayTo)) ||
                                ((eobj.dtStayFrom <= p.dtStayFrom && eobj.dtStayTo >= p.dtStayFrom) || (eobj.dtStayFrom <= p.dtStayTo && eobj.dtStayTo >= p.dtStayTo)))
                            );
                    }
                    else
                    {
                        checkExists = db.tblPropertyTaxMaps.Any(
                            p => p.iPropId == eobj.iPropId &&
                            ((p.iRoomId == null) || (p.iRoomId != null && p.cStatus == "A")) &&
                            p.iPropTaxId != eobj.iPropTaxId &&
                            (((p.dtStayFrom <= eobj.dtStayFrom && p.dtStayTo >= eobj.dtStayFrom) || (p.dtStayFrom <= eobj.dtStayTo && p.dtStayTo >= eobj.dtStayTo)) ||
                             ((eobj.dtStayFrom <= p.dtStayFrom && eobj.dtStayTo >= p.dtStayFrom) || (eobj.dtStayFrom <= p.dtStayTo && eobj.dtStayTo >= p.dtStayTo)))
                            );
                    }

                    if (checkExists != true)
                    {
                        using (OneFineRateEntities db1 = new OneFineRateEntities())
                        {
                            OneFineRate.tblPropertyTaxMap obj = (OneFineRate.tblPropertyTaxMap)OneFineRateAppUtil.clsUtils.ConvertToObject(eobj, new OneFineRate.tblPropertyTaxMap());
                            db1.tblPropertyTaxMaps.Attach(obj);
                            db1.Entry(obj).State = System.Data.Entity.EntityState.Modified;

                            //remove old mapings
                            db1.tblPropertyTaxesMaps.RemoveRange(db1.tblPropertyTaxesMaps.Where(x => x.iPropTaxId == eobj.iPropTaxId));

                            if (eobj.PropertyTaxesList != null)
                            {
                                db1.tblPropertyTaxesMaps.AddRange(eobj.PropertyTaxesList.Select(x => new tblPropertyTaxesMap()
                                {
                                    iPropTaxId   = eobj.iPropTaxId,
                                    iTaxId       = x.iTaxId,
                                    bIsPercent   = x.bIsPercent,
                                    dValue       = x.dValue,
                                    dtActionDate = x.dtActionDate,
                                    iActionBy    = x.iActionBy
                                }).ToList());
                            }

                            db1.SaveChanges();



                            #region Propperty Room Tax List

                            //db1.tblPropertyRoomTaxMaps.RemoveRange(db1.tblPropertyRoomTaxMaps.Where(n => n.iPropTaxId == eobj.iPropTaxId));

                            SqlParameter[] MyParam = new SqlParameter[1];
                            MyParam[0] = new SqlParameter("@PropTaxId", eobj.iPropTaxId);

                            db.Database.ExecuteSqlCommand("uspRemovetblPropertyRoomTaxMaps @PropTaxId", MyParam);


                            List <PropertyRoomTaxList> LPRPC = new List <PropertyRoomTaxList>();
                            if (eobj.iRoomId != null)
                            {
                                DateTime CurrentDate = (DateTime)eobj.dtStayFrom;
                                while (CurrentDate <= eobj.dtStayTo)
                                {
                                    PropertyRoomTaxList PRPC = new PropertyRoomTaxList();
                                    PRPC.dtStay       = CurrentDate;
                                    PRPC.iPropTaxId   = eobj.iPropTaxId;
                                    PRPC.iPropId      = eobj.iPropId;
                                    PRPC.iRoomId      = (long)eobj.iRoomId;
                                    PRPC.iActionBy    = (int)eobj.iActionBy;
                                    PRPC.dtActionDate = DateTime.Now;
                                    PRPC.cStatus      = eobj.cStatus;

                                    LPRPC.Add(PRPC);
                                    CurrentDate = CurrentDate.AddDays(1);
                                }
                            }
                            else
                            {
                                List <PNames> objRoomList = new List <PNames>();
                                objRoomList = BL_tblPropertyRoomMap.GetAllPropertyTypes(eobj.iPropId);
                                foreach (var item in objRoomList)
                                {
                                    DateTime CurrentDate = (DateTime)eobj.dtStayFrom;
                                    while (CurrentDate <= eobj.dtStayTo)
                                    {
                                        PropertyRoomTaxList PRPC = new PropertyRoomTaxList();
                                        PRPC.dtStay       = CurrentDate;
                                        PRPC.iPropTaxId   = eobj.iPropTaxId;;
                                        PRPC.iPropId      = eobj.iPropId;
                                        PRPC.iRoomId      = Convert.ToInt64(item.Id);
                                        PRPC.iActionBy    = (int)eobj.iActionBy;
                                        PRPC.dtActionDate = DateTime.Now;
                                        PRPC.cStatus      = eobj.cStatus;

                                        LPRPC.Add(PRPC);
                                        CurrentDate = CurrentDate.AddDays(1);
                                    }
                                }
                            }

                            if (LPRPC != null)
                            {
                                db.tblPropertyRoomTaxMaps.AddRange(LPRPC.Select(m => new tblPropertyRoomTaxMap()
                                {
                                    dtStay       = m.dtStay,
                                    iPropTaxId   = m.iPropTaxId,
                                    iPropId      = m.iPropId,
                                    iRoomId      = (long)m.iRoomId,
                                    dtActionDate = m.dtActionDate,
                                    iActionBy    = m.iActionBy,
                                    cStatus      = m.cStatus
                                }));
                            }

                            db.SaveChanges();
                            #endregion
                            retval = 1;
                        }
                    }
                    else
                    {
                        retval = 2;
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return(retval);
        }