Example #1
0
        public string SaveUpdateTenantStorage(TenantStorageModel model)
        {
            ShomaRMEntities db = new ShomaRMEntities();
            decimal         totalStorageAmt = 0;
            string          result          = "";

            if (model.lstTStorage != null)

            {
                // check storage available //
                long storageid = model.lstTStorage[0].StorageID ?? 0;

                var storagedata        = db.tbl_Storage.Where(p => p.StorageID == storageid).FirstOrDefault();
                var isStorageAvailable = db.tbl_TenantStorage.Where(p => p.StorageID == storageid && TenantID != model.TenantID).FirstOrDefault();
                if (isStorageAvailable != null)
                {
                    result = "0|" + storagedata.StorageName + " - " + storagedata.Description + " is not available.<br/>Please select other storage unit.|0.00";
                }
                // check storage available //
                else
                {
                    var TenantStorageData = db.tbl_TenantStorage.Where(p => p.TenantID == model.TenantID).ToList();
                    db.tbl_TenantStorage.RemoveRange(TenantStorageData);
                    db.SaveChanges();

                    foreach (var cd in model.lstTStorage)
                    {
                        var cdData = new tbl_TenantStorage
                        {
                            StorageID   = cd.StorageID,
                            TenantID    = model.TenantID,
                            Charges     = storagedata.Charges,
                            CreatedDate = Convert.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy"))
                        };
                        db.tbl_TenantStorage.Add(cdData);
                        db.SaveChanges();
                        totalStorageAmt = totalStorageAmt + Convert.ToDecimal(storagedata.Charges);
                    }

                    result = "1|Progress saved|" + totalStorageAmt.ToString();
                }
            }
            else
            {
                var TenantStorageData = db.tbl_TenantStorage.Where(p => p.TenantID == model.TenantID).ToList();
                db.tbl_TenantStorage.RemoveRange(TenantStorageData);
                db.SaveChanges();
                result = "1|Progress saved|0.00";
            }
            return(result);
        }
Example #2
0
        public List <TenantStorageModel> GetTenantStorageList(long TenantId)
        {
            ShomaRMEntities           db    = new ShomaRMEntities();
            List <TenantStorageModel> model = new List <TenantStorageModel>();

            try
            {
                DataTable dtTable = new DataTable();
                using (var cmd = db.Database.Connection.CreateCommand())
                {
                    db.Database.Connection.Open();
                    cmd.CommandText = "usp_Get_TenantStorage";
                    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)
                {
                    TenantStorageModel usm = new TenantStorageModel();
                    usm.TSID        = Convert.ToInt64(dr["TSID"].ToString());
                    usm.StorageID   = Convert.ToInt64(dr["StorageID"].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;
            }
        }