public void SaveProducts(List <Product> products) { ImeshmaEntities _db = new ImeshmaEntities(); _db.Products.AddRange(products); _db.SaveChanges(); }
public List <Product> GetProductDetails() { List <Product> _productList; try { using (_db = new ImeshmaEntities()) { DbDataReader _reader; //_db.Database.Initialize(force: false); _db.Database.Connection.Open(); DbCommand _dbCmd = _db.Database.Connection.CreateCommand(); _dbCmd.CommandText = "GetProductDetails"; _dbCmd.CommandType = CommandType.StoredProcedure; _dbCmd.CommandTimeout = 60 * 5; //_dbCmd.Parameters.AddRange(new SqlParameter[] { // new SqlParameter("@Drugname",DrugName ), // new SqlParameter("@CountryId",CountryId ), // new SqlParameter("@UserId",UserID ), // new SqlParameter("@IsMedicine",IsMedicine) //}); _reader = _dbCmd.ExecuteReader(); _productList = ((IObjectContextAdapter)_db).ObjectContext.Translate <Product>(_reader).ToList(); } } catch (Exception ex) { throw ex; } finally { //if (_db.Database.Connection.State == ConnectionState.Open) //{ // _db.Database.Connection.Close(); //} } return(_productList); }
public void AddUser(UserModel model) { try { ImeshmaEntities _db = new ImeshmaEntities(); _db.Users.Add( new User() { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, CreatedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow, LoginVia = model.LoginVia } ); _db.SaveChanges(); } catch { throw; } }
// GET: Products public ActionResult Index() { ImeshmaEntities _db = new ImeshmaEntities(); return(View(_db.GetProductDetails(null))); }
public List <Category> GetCategories() { ImeshmaEntities _db = new ImeshmaEntities(); return(_db.Categories.ToList()); }