public List <Product> GetAll() { List <Product> products = new List <Product>(); using (var db = new StoreDBEntities()) { foreach (var p in db.GetAllProducts()) { Product product = new Product(); product.ID = p.ID; product.Prod_Name = p.Product_Name; product.Price = p.Price; product.Category_ID = p.Category_ID; product.Category_Name = p.Category_Name; product.Currency_ID = p.Currency_ID; product.Currency_Name = p.Currency_Name; product.Unit_ID = p.Unit_ID; product.Unit_Name = p.Unit_Name; products.Add(product); } } return(products); }
public IEnumerable <Employee> Get() { using (StoreDBEntities empEntities = new StoreDBEntities()) { return(empEntities.Employees.ToList()); } }
public HttpResponseMessage Get(string gender = "All") { string username = Thread.CurrentPrincipal.Identity.Name; using (StoreDBEntities empEntities = new StoreDBEntities()) { switch (gender.ToLower()) { case "All": return(Request.CreateResponse(HttpStatusCode.OK, empEntities.Employees.ToList())); case "male": return(Request.CreateResponse(HttpStatusCode.OK, empEntities.Employees.Where(e => e.Gender.ToLower() == "male"))); case "female": return(Request.CreateResponse(HttpStatusCode.OK, empEntities.Employees.Where(e => e.Gender.ToLower() == "female"))); default: return(Request.CreateResponse(HttpStatusCode.BadRequest)); // default: // return Request.CreateResponse(HttpStatusCode.OK, empEntities.Employees.ToList()); // default: // return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Value for Gender must be" + // " 'all', 'male' or 'female'"); } } }
public HttpResponseMessage Put([FromBody] int id, [FromUri] Employee employee) { try { using (StoreDBEntities empEntities = new StoreDBEntities()) { var entity = empEntities.Employees.FirstOrDefault(e => e.ID == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"No Employee with ID: {id} found to update")); } else { entity.FirstName = employee.FirstName; entity.LastName = employee.LastName; entity.Gender = employee.Gender; entity.Salary = employee.Salary; empEntities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } } }catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public void EmptyDbTable_ByManyThreads_UsingQueue() { StoreDBEntities storeDB = new StoreDBEntities(); // Формируем коллекцию заказов для запросов к БД List <Order> ordersToServe = new List <Order>(); Random rn = new Random(); for (int i = 0; i < 1000; i++) { ordersToServe.Add(new Order() { BuyerName = $"Byuer Number {i}", OrderName = "Some order", OrderNumber = (byte)rn.Next(1, 5) }); } // Запускаем запросы к БД в асинхронном режиме foreach (Order o in ordersToServe) { StartQueries.BeginInvoke(o.BuyerName, o.OrderName, o.OrderNumber, storeDB, new AsyncCallback(StartQueriesFinish), null); } finishOfQueriesFlag.WaitOne(); // Проверяем, что сумма купленных товаров, равноа 100 Assert.AreEqual(100, ServedOrderCollection.Where(o => o.IsOrderReady == true).Sum(o => o.OrderNumber)); }
public ActionResult Merchandise([Bind(Include = "make,style,price,engine,file.FileName,description")] Merchandise merchandise, HttpPostedFileBase file) { if (ModelState.IsValid) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Home/images"), fileName); file.SaveAs(path); //string make, style, engine, imageURL, description; // double price = 0; string imageURL; imageURL = fileName; // make = Request.Form["make"]; // style = Request.Form["style"]; // description = Request.Form["description"]; // price = Double.Parse(Request.Form["price"]); // Convert.ToDouble() // engine = Request.Form["engine"]; // Merchandise merchandise = new Merchandise(1005, make, style, price, //engine, imageURL, description); var db = new StoreDBEntities(); db.Merchandises.Add(merchandise); db.SaveChanges(); ViewBag.Message = "Upload successful"; return(RedirectToAction("Index")); } return(View()); }
public HttpResponseMessage Delete(int id) { try { using (StoreDBEntities empEntities = new StoreDBEntities()) { var entity = empEntities.Employees.FirstOrDefault(e => e.ID == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"Employee with ID: {id} Not Found to delete")); } else { empEntities.Employees.Remove(entity); empEntities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } }catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public static Boolean Login(string username, string password) { using (StoreDBEntities entities = new StoreDBEntities()) { return(entities.Users.Any(user => user.Username.Equals(username, StringComparison.OrdinalIgnoreCase) && user.Password == password)); } }
public bool Delete(int ID) { using (var db = new StoreDBEntities()) { var returnID = db.DeleteCategory(ID).FirstOrDefault(); return(returnID != null && returnID > 0); } }
public bool Update(Category obj) { using (var db = new StoreDBEntities()) { var returnID = db.UpdateCategory(obj.ID, obj.Category_Name).FirstOrDefault(); return(returnID != null && returnID > 0); } }
public bool Add(Product obj) { using (var db = new StoreDBEntities()) { var returnID = db.CreateProduct( obj.Prod_Name, obj.Category_ID, obj.Unit_ID, obj.Price, obj.Currency_ID) .FirstOrDefault(); return(returnID != null && returnID > 0); } }
public string InsertProductType(ProductType productType) { try { StoreDBEntities db = new StoreDBEntities(); db.ProductTypes.Add(productType); db.SaveChanges(); return(productType.Name + " was succesfully inserted"); } catch (Exception e) { return("Error:" + e); } }
public string InsertCart(Cart cart) { try { StoreDBEntities db = new StoreDBEntities(); db.Carts.Add(cart); db.SaveChanges(); return(cart.DatePurchased + " was succesfully inserted"); } catch (Exception e) { return("Error:" + e); } }
public List <Unit> GetAll() { List <Unit> units = new List <Unit>(); using (var db = new StoreDBEntities()) { foreach (var u in db.GetAllUnits()) { var unit = new Unit(); unit.ID = u.ID; unit.Unit_Name = u.Unit_Name; units.Add(unit); } } return(units); }
public HttpResponseMessage EmployeeByID(int id) { using (StoreDBEntities empEnitities = new StoreDBEntities()) { var entity = empEnitities.Employees.FirstOrDefault(e => e.ID == id); if (entity != null) { return(Request.CreateResponse(HttpStatusCode.OK, entity)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"Employee with {id} Not Found")); } } }
public Category GetByID(int ID) { Category category = new Category(); using (var db = new StoreDBEntities()) { var c = db.GetCategory(ID).FirstOrDefault(); if (c != null) { category.ID = c.ID; category.Category_Name = c.Category_Name; category.InUse = c.In_Use.Equals(1); } } return(category); }
/// <summary> /// Dodawanie produktu do bazy /// </summary> public static bool addProduct(StoreDBEntities db, Category c, string name, double price) { try { Product p = new Product(); p.name = name; p.price = price; p.Category_Id = c.Category_Id; db.Products.Add(p); db.SaveChanges(); } catch (Exception ex) { return(false); } return(true); }
//Return a list of all available products in database public List <Product> GetAllProducts() { try { using (StoreDBEntities db = new StoreDBEntities()) { //select * from products then converts all the items grabbed into a list so we can use it in our code List <Product> products = (from x in db.Products select x).ToList(); //Returns product afterwards. return(products); } } catch (Exception e) { return(null); } }
// Return a single product object using product's id number public Product GetProduct(int id) { try { //Creates a new Store database and set the product that we are searching for in place for the original //Returns that product using (StoreDBEntities db = new StoreDBEntities()) { Product product = db.Products.Find(id); return(product); } } catch (Exception e) { //If something goes wrong returns null return(null); } }
public string DeleteCart(int id) { try { StoreDBEntities db = new StoreDBEntities(); Cart cart = db.Carts.Find(id); db.Carts.Attach(cart); db.Carts.Remove(cart); db.SaveChanges(); return(cart.DatePurchased + " was succesfully deleted"); } catch (Exception e) { return("Error:" + e); } }
public List <tblProduct> GetProducts() { try { using (StoreDBEntities context = new StoreDBEntities()) { List <tblProduct> list = new List <tblProduct>(); list = (from x in context.tblProducts select x).ToList(); return(list); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public List <Category> GetAll() { List <Category> categories = new List <Category>(); using (var db = new StoreDBEntities()) { foreach (var c in db.GetAllCategories()) { Category category = new Category(); category.ID = c.ID; category.Category_Name = c.Category_Name; category.InUse = c.In_Use.Equals(1); categories.Add(category); } } return(categories); }
public string DeleteProductType(int id) { try { StoreDBEntities db = new StoreDBEntities(); ProductType productType = db.ProductTypes.Find(id); db.ProductTypes.Attach(productType); db.ProductTypes.Remove(productType); db.SaveChanges(); return(productType.Name + " was succesfully deleted"); } catch (Exception e) { return("Error:" + e); } }
public tblProduct GetProductByName(string name) { try { using (StoreDBEntities context = new StoreDBEntities()) { tblProduct product = (from x in context.tblProducts where x.ProductName == name select x).First(); return(product); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
//Return a list of products that have the same selected type private List <Product> GetProductsByType(int typeId) { try { using (StoreDBEntities db = new StoreDBEntities()) { //select and grab all products where typeId is == to the id that the users chooses //Returns product afterwards. List <Product> products = (from x in db.Products where x.TypeId == typeId select x).ToList(); return(products); } } catch (Exception e) { return(null); } }
public ActionResult SignUp([Bind(Include = "username,name,lastName,password")] User user) { if (ModelState.IsValid) { var db = new StoreDBEntities(); //string username, name, lastName, password; //username = Request.Form["username"]; //name = Request.Form["name"]; //lastName = Request.Form["lastname"]; //password = Request.Form["password"]; //CarSalesApp1.User user = new CarSalesApp1.User(username, name, lastName, password); //using (var db = new CarSalesApp1.StoreDBEntities()) db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
public string UpdateProductType(int id, ProductType productType) { try { StoreDBEntities db = new StoreDBEntities(); //Fetch object from db ProductType p = db.ProductTypes.Find(id); p.Name = productType.Name; db.SaveChanges(); return(productType.Name + " was succesfully updated"); } catch (Exception e) { return("Error:" + e); } }
public HttpResponseMessage Post([FromBody] Employee employee) { try { using (StoreDBEntities empEntities = new StoreDBEntities()) { empEntities.Employees.Add(employee); empEntities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, employee); // Below, the ID of the object is included so that it can be found message.Headers.Location = new Uri(Request.RequestUri + employee.ID.ToString()); return(message); } }catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex)); } }
public string InsertProduct(Product product) { try { //We are trying to add new products to the database which means we need to create a new StoreDBEntities StoreDBEntities db = new StoreDBEntities(); //call the db which we created above and connected it with Products which is in our entity then use the add call function to //add the product that the owner wants to add. db.Products.Add(product); //Have to make sure we save the changes that we just made so we use the method SaveChanges() db.SaveChanges(); //here we just return the product's name and tell the user that the item was successfully added. return(product.Name + " was succesfully inserted"); } catch (Exception e) { //if there is a error the catch will return error return("Error:" + e); } }
public void RemoveProduct(int productId) { try { using (StoreDBEntities context = new StoreDBEntities()) { tblProduct productToDelete = (from u in context.tblProducts where u.ID == productId select u).First(); context.tblProducts.Remove(productToDelete); context.SaveChanges(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); } }