Пример #1
0
        //public string  SaveUpdateTenantParking(TenantParkingModel model)
        //{
        //    ShomaRMEntities db = new ShomaRMEntities();
        //    decimal totalParkingAmt = 0;
        //    int numOfParking = 0;
        //    string result = "";
        //    long addParking = 0;
        //    long deleteParking = 0;
        //    if (model.lstTParking != null)
        //    {
        //        long parkingNumber = model.lstTParking[0].ParkingID ?? 0;
        //        // check storage available //
        //        var tenantParkingData = db.tbl_TenantParking.Where(p => p.TenantID == model.TenantID).ToList();
        //        if (tenantParkingData.Count >0)
        //        {
        //            if (tenantParkingData.Count != parkingNumber)
        //            {
        //                long parkingDiff = tenantParkingData.Count - parkingNumber;
        //                if(parkingDiff<0)
        //                {
        //                    addParking = -1 * parkingDiff;
        //                }else
        //                {
        //                    deleteParking = parkingDiff;
        //                }

        //                foreach (var tpd in tenantParkingData)
        //                {
        //                    var remparkingdata = db.tbl_Parking.Where(p => p.PropertyID == model.UID && p.Type == 2 && p.ParkingID == tpd.ParkingID).FirstOrDefault();
        //                    if (remparkingdata != null)
        //                    {
        //                        remparkingdata.PropertyID = 0;
        //                        db.SaveChanges();
        //                    }
        //                }
        //                db.tbl_TenantParking.RemoveRange(tenantParkingData);
        //                db.SaveChanges();
        //            }
        //        }
        //        else
        //        {
        //            addParking = parkingNumber;
        //        }


        //        var parkingdata = db.tbl_Parking.Where(p => p.ParkingID == parkingid).FirstOrDefault();
        //        var isParkingAvailable = db.tbl_TenantParking.Where(p => p.ParkingID == parkingid && TenantID != model.TenantID).FirstOrDefault();
        //        if (isParkingAvailable != null)
        //        {
        //            result = "0|" + parkingdata.ParkingName + " - " + parkingdata.Description + " is not available.<br/>Please select other parking unit.|0|0.00";
        //        }
        //        // check storage available //
        //        else
        //        {
        //            var tenantParkingData = db.tbl_TenantParking.Where(p => p.TenantID == model.TenantID).ToList();

        //            if (tenantParkingData != null)
        //            {
        //                foreach (var tpd in tenantParkingData)
        //                {
        //                    var remparkingdata = db.tbl_Parking.Where(p => p.PropertyID == model.UID && p.Type == 2 && p.ParkingID == tpd.ParkingID).FirstOrDefault();
        //                    if (remparkingdata != null)
        //                    {
        //                        remparkingdata.PropertyID = 0;
        //                        db.SaveChanges();
        //                    }
        //                }
        //                db.tbl_TenantParking.RemoveRange(tenantParkingData);
        //                db.SaveChanges();
        //            }

        //            foreach (var cd in model.lstTParking)
        //            {
        //                var cdData = new tbl_TenantParking
        //                {
        //                    ParkingID = cd.ParkingID,
        //                    TenantID = model.TenantID,
        //                    Charges = parkingdata.Charges,
        //                    CreatedDate = Convert.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy"))
        //                };
        //                db.tbl_TenantParking.Add(cdData);
        //                db.SaveChanges();
        //                numOfParking = numOfParking + parkingdata.Type ?? 0;
        //                totalParkingAmt = totalParkingAmt + Convert.ToDecimal(parkingdata.Charges);
        //                parkingdata.PropertyID = model.UID;
        //                db.SaveChanges();
        //            }
        //            result = "1|Progress saved|"+ numOfParking + "|"+ totalParkingAmt.ToString();
        //        }

        //    }
        //    else
        //    {
        //        var tenantParkingData = db.tbl_TenantParking.Where(p => p.TenantID == model.TenantID).ToList();
        //        if (tenantParkingData != null)
        //        {
        //            foreach (var tpd in tenantParkingData)
        //            {
        //                var remparkingdata = db.tbl_Parking.Where(p => p.PropertyID == model.UID && p.Type == 2 && p.ParkingID == tpd.ParkingID).FirstOrDefault();
        //                if (remparkingdata != null)
        //                {
        //                    remparkingdata.PropertyID = 0;
        //                    db.SaveChanges();
        //                }
        //            }
        //            db.tbl_TenantParking.RemoveRange(tenantParkingData);
        //            db.SaveChanges();
        //        }
        //        result = "1|Progress saved|0|0.00";
        //    }
        //    return result;
        //}

        public string SaveUpdateTenantParking(TenantParkingModel model)
        {
            ShomaRMEntities db           = new ShomaRMEntities();
            long            numOfParking = 0;
            long            unitID       = model.UID;
            long            tenantID     = model.TenantID ?? 0;

            if (model.lstTParking != null)
            {
                if (model.lstTParking.Count > 0)
                {
                    numOfParking = model.lstTParking[0].ParkingID ?? 0;
                }
            }
            string    result  = "";
            DataTable dtTable = new DataTable();

            using (var cmd = db.Database.Connection.CreateCommand())
            {
                db.Database.Connection.Open();
                cmd.CommandText = "usp_SaveUpdateTenantParking";
                cmd.CommandType = CommandType.StoredProcedure;

                DbParameter paramNOP = cmd.CreateParameter();
                paramNOP.ParameterName = "NumberOfParking";
                paramNOP.Value         = numOfParking;
                cmd.Parameters.Add(paramNOP);

                DbParameter paramUID = cmd.CreateParameter();
                paramUID.ParameterName = "UnitID";
                paramUID.Value         = unitID;
                cmd.Parameters.Add(paramUID);

                DbParameter paramTID = cmd.CreateParameter();
                paramTID.ParameterName = "TenantID";
                paramTID.Value         = tenantID;
                cmd.Parameters.Add(paramTID);

                DbDataAdapter da = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateDataAdapter();
                da.SelectCommand = cmd;
                da.Fill(dtTable);
                db.Database.Connection.Close();
            }
            if (dtTable.Rows.Count > 0)
            {
                result = dtTable.Rows[0][0].ToString();
            }
            else
            {
                result = "1|Error Occured. Please try again.d|0|0.00";
            }
            db.Dispose();

            return(result);
        }
Пример #2
0
        public List <TenantParkingModel> GetTenantParkingList(long TenantId)
        {
            ShomaRMEntities           db    = new ShomaRMEntities();
            List <TenantParkingModel> model = new List <TenantParkingModel>();

            try
            {
                DataTable dtTable = new DataTable();
                using (var cmd = db.Database.Connection.CreateCommand())
                {
                    db.Database.Connection.Open();
                    cmd.CommandText = "usp_Get_TenantParking";
                    cmd.CommandType = CommandType.StoredProcedure;

                    DbParameter paramC = cmd.CreateParameter();
                    paramC.ParameterName = "TenantId";
                    paramC.Value         = TenantId;
                    cmd.Parameters.Add(paramC);

                    DbDataAdapter da = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateDataAdapter();
                    da.SelectCommand = cmd;
                    da.Fill(dtTable);
                    db.Database.Connection.Close();
                }
                foreach (DataRow dr in dtTable.Rows)
                {
                    TenantParkingModel usm = new TenantParkingModel();
                    usm.TPID        = Convert.ToInt64(dr["TPID"].ToString());
                    usm.ParkingID   = Convert.ToInt64(dr["ParkingID"].ToString());
                    usm.TenantID    = Convert.ToInt64(dr["TenantID"].ToString());
                    usm.Charges     = Convert.ToDecimal(dr["Charges"].ToString());
                    usm.CreatedDate = Convert.ToDateTime(dr["CreatedDate"].ToString());
                    model.Add(usm);
                }
                db.Dispose();
                return(model.ToList());
            }
            catch (Exception ex)
            {
                db.Database.Connection.Close();
                throw ex;
            }
        }