public List <StorageModel> GetStorageList(long TenantID, string OrderBy, string SortBy) { ShomaRMEntities db = new ShomaRMEntities(); List <StorageModel> model = new List <StorageModel>(); try { DataTable dtTable = new DataTable(); using (var cmd = db.Database.Connection.CreateCommand()) { db.Database.Connection.Open(); cmd.CommandText = "usp_Get_Storage"; cmd.CommandType = CommandType.StoredProcedure; DbParameter paramTID = cmd.CreateParameter(); paramTID.ParameterName = "TenantID"; paramTID.Value = TenantID; cmd.Parameters.Add(paramTID); DbParameter paramOB = cmd.CreateParameter(); paramOB.ParameterName = "OrderBy"; paramOB.Value = OrderBy; cmd.Parameters.Add(paramOB); DbParameter paramSB = cmd.CreateParameter(); paramSB.ParameterName = "SortBy"; paramSB.Value = SortBy; cmd.Parameters.Add(paramSB); DbDataAdapter da = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateDataAdapter(); da.SelectCommand = cmd; da.Fill(dtTable); db.Database.Connection.Close(); } foreach (DataRow dr in dtTable.Rows) { StorageModel usm = new StorageModel(); usm.StorageID = int.Parse(dr["StorageID"].ToString()); usm.PropertyID = int.Parse(dr["PropertyID"].ToString()); usm.StorageName = dr["StorageName"].ToString(); usm.Charges = Convert.ToDecimal(dr["Charges"].ToString()); usm.Description = dr["Description"].ToString(); usm.Type = int.Parse(dr["Type"].ToString()); model.Add(usm); } db.Dispose(); return(model.ToList()); } catch (Exception ex) { db.Database.Connection.Close(); throw ex; } }
public StorageModel GetStorageData(int Id) { ShomaRMEntities db = new ShomaRMEntities(); StorageModel model = new StorageModel(); var GetStorageData = db.tbl_Storage.Where(p => p.StorageID == Id).FirstOrDefault(); if (GetStorageData != null) { model.StorageID = GetStorageData.StorageID; model.PropertyID = GetStorageData.PropertyID; model.StorageName = GetStorageData.StorageName; model.Charges = GetStorageData.Charges; model.Description = GetStorageData.Description; } model.StorageID = Id; return(model); }
public StorageModel GetStorageInfo(int ID = 0) { ShomaRMEntities db = new ShomaRMEntities(); StorageModel model = new StorageModel(); model.StorageID = 0; model.StorageName = ""; var StorageInfo = db.tbl_Storage.Where(p => p.StorageID == StorageID).FirstOrDefault(); if (StorageInfo != null) { model.StorageID = StorageInfo.StorageID; model.PropertyID = StorageInfo.PropertyID; model.StorageName = StorageInfo.StorageName; model.Charges = StorageInfo.Charges; model.Description = StorageInfo.Description; } return(model); }
public long SaveUpdateStorage(StorageModel model) { ShomaRMEntities db = new ShomaRMEntities(); if (model.StorageID != 0) { var StorageInfo = db.tbl_Storage.Where(p => p.StorageID == model.StorageID).FirstOrDefault(); if (StorageInfo != null) { StorageInfo.PropertyID = model.PropertyID; StorageInfo.StorageName = model.StorageName; StorageInfo.Charges = model.Charges; StorageInfo.Description = model.Description; db.SaveChanges(); } else { throw new Exception(model.StorageName + " not exists in the system."); } } return(model.StorageID); }