public IHttpActionResult PutVAT(int id, VAT vAT) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != vAT.Vat_ID) { return(BadRequest()); } db.Entry(vAT).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!VATExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutPMethod(int id, PMethod pMethod) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != pMethod.PMethod_ID) { return(BadRequest()); } db.Entry(pMethod).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PMethodExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutTopping(int id, Topping topping) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != topping.Topping_ID) { return(BadRequest()); } db.Entry(topping).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ToppingExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Register(RegisterViewModel customer) { if (ModelState.IsValid) { if (getCustomerByUsername(customer.Username) != null) { ModelState.AddModelError(string.Empty, "Benutzername bereits vergeben."); return(View(customer)); } Customer c = new Customer { Firstname = customer.Firstname, Lastname = customer.Lastname, Street = customer.Street, Housenumber = customer.Housenumber, City = customer.City, Zipcode = customer.Zipcode, PhoneNumber = customer.PhoneNumber, EmailAddress = customer.EmailAddress, Username = customer.Username }; c.PasswordHash = Cryptography.Hash(customer.Password); db.Customers.Add(c); db.SaveChanges(); return(View("Login")); } return(View(customer)); }
public IHttpActionResult PutOrder_Status(int id, Order_Status order_Status) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != order_Status.Order_Status_ID) { return(BadRequest()); } db.Entry(order_Status).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!Order_StatusExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutEmployee(int id, Employee employee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employee.Employee_ID) { return(BadRequest()); } db.Entry(employee).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void test_Repository_saveTopping() { Topping topping = new Topping { id = 1, description = "ham is good", name = "Ham" }; using (var context = new PizzaShopEntities()) { context.Toppings.Add(topping); context.SaveChanges(); } }
public void test_Repository_savePizza() { Pizza pizza = new Pizza { id = 1, description = "delicious pizza", name = "Irish" }; using (var context = new PizzaShopEntities()) { context.Pizzas.Add(pizza); context.SaveChanges(); } }
public ActionResult Finished() { var cart = Session["cart"] as List <CartViewModel>; var customerId = Convert.ToInt32(Session["CurrentCustomerID"]); var orderDate = DateTime.Now; Order order = new Order { CustomerID = customerId, Status = 2, OrderDate = orderDate }; db.Orders.Add(order); db.SaveChanges(); var dbOrder = db.Orders.OrderByDescending(o => o.ID).First(); foreach (var p in cart) { OrderHasProduct ohp = new OrderHasProduct { OrderID = dbOrder.ID, ProductID = p.ProductID, Quantity = p.Quantity }; db.OrderHasProducts.Add(ohp); foreach (var t in p.Toppings) { OrderHasProduct oht = new OrderHasProduct { OrderID = dbOrder.ID, ProductID = t.ID, Quantity = 1 }; db.OrderHasProducts.Add(oht); } } db.SaveChanges(); return(View()); }
public ActionResult Register(Customer customer) { bool Status = false; string message = ""; if (ModelState.IsValid) { #region Username exists if (UsernameExists(customer.Username)) { ModelState.AddModelError("UsernameExists", "Username is already taken"); return(View(customer)); } #endregion #region Password Hashing customer.PasswordHash = Cryptography.Hash(customer.PasswordHash); customer.ConfirmPassword = Cryptography.Hash(customer.ConfirmPassword); // #endregion //customer.IsEmailVerified = false; #region Save to db.Customer.Add(customer); db.SaveChanges(); /* * //Send Email to User * SendVerificationLinkEmail(user.EmailID, user.ActivationCode.ToString()); * message = "Registration successfully done. Account activation link " + * " has been sent to your email id:" + user.EmailID; */ message = "Registration Successfull!"; Status = true; #endregion } else { message = "Invalid Request"; } ViewBag.Message = message; ViewBag.Status = Status; ViewBag.CustomerData = customer; return(View()); }
public ActionResult Create(Customer customer) { try { if (ModelState.IsValid) { customer.PasswordHash = Cryptography.Hash(customer.Password); db.Customer.Add(customer); db.SaveChanges(); return(RedirectToAction("CustomersList")); } } catch (RetryLimitExceededException) { ModelState.AddModelError("", "Unable to save changes."); } return(View(customer)); }
public ActionResult EditProduct(EditProductViewModel product) { //if (product.Price < 0) //{ // ModelState.AddModelError(string.Empty, "Preis darf nicht kleiner als Null sein"); // product.Price = db.Products.Find(product.ID).Price; // return View(product); //} if (ModelState.IsValid) { var dbProd = db.Products.Find(product.ID); dbProd.CategoryID = product.SelectedCategoryID; dbProd.Name = product.Name; dbProd.Price = product.Price; dbProd.IsInSortiment = product.IsInSortiment; //var x = db.ProductHasAllergens.Where(a => allergens.Contains(a.ProductID)).ToList(); //foreach (var i in allergens) //{ // if (x.FirstOrDefault(a => a.AllergenID == i) == null) // { // x // } //} db.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError(string.Empty, "Ungültige Daten"); } return(View(product)); }