public IHttpActionResult PutProduct(int id, Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product.ID) { return(BadRequest()); } db.Entry(product).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IActionResult Create(Category obj) { if (ModelState.IsValid) { _db.Category.Add(obj); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(obj)); }
public ActionResult Create([Bind(Include = "Branch_id,Branch_name,Branch_Address,Branch_Contact")] Branch branch) { if (ModelState.IsValid) { db.Branch.Add(branch); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(branch)); }
public ActionResult Create([Bind(Include = "Teacher_id,Teacher_Name,Teacher_FatherName,Dateofjoin,Branch_id")] Teacher teacher) { if (ModelState.IsValid) { db.Teacher.Add(teacher); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Branch_id = new SelectList(db.Branch, "Branch_id", "Branch_name", teacher.Branch_id); return(View(teacher)); }
public ActionResult Register(Users users) { users.user_role = "Teacher"; users.status = true; if (ModelState.IsValid) { db.Users.Add(users); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(users)); }
private static void AddRoles(ApplicationDbcontext dbcontext) { if (dbcontext.Roles.Any()) { return; } foreach (IdentityRole role in Roles) { dbcontext.Roles.Add(role); dbcontext.SaveChanges(); } }
/// <summary> /// adds roles to database /// </summary> /// <param name="context">which database</param> private static void AddRoles(ApplicationDbcontext context) { if (context.Roles.Any()) { return; } foreach (var role in Roles) { context.Roles.Add(role); context.SaveChanges(); } }
// PUT: api/Catagories/5 public IHttpActionResult PutCatagory(int id, Catagory catagory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != catagory.ID) { return(BadRequest()); } var c = (from i in db.Catagories where i.ID == id select i).FirstOrDefault(); c.Name = catagory.Name; db.SaveChanges(); try { //db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CatagoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostOrder(order order) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var x = (from i in db.Users where i.UserName == order.CustomerName select i.Id).FirstOrDefault(); Orders ord = new Orders(); ord.OrderUserProduct = order.item; ord.TotalOrderCash = order.TotalOrderCash; ord.CustomerId = x; db.Orders.Add(ord); db.SaveChanges(); return(Ok()); }
public ActionResult Create(Branch branch_obj) { db.Branch.Add(branch_obj); db.SaveChanges(); return(RedirectToAction("Index")); }
public void SavePermissionType() { _dbcontext.SaveChanges(); }
public static void EnsurePopulated(IApplicationBuilder app) { ApplicationDbcontext context = app.ApplicationServices.GetRequiredService <ApplicationDbcontext>(); if (!context.Products.Any()) { context.Products.AddRange( new Product { Name = "Kayak", Description = "A boat for one person", Category = "Watersports", Price = 275 }, new Product { Name = "Lifejacket", Description = "Protective and fashionable", Category = "Watersports", Price = 48.95m }, new Product { Name = "Soccer Ball", Description = "FIFA-approved size and weight", Category = "Soccer", Price = 19.50m }, new Product { Name = "Corner Flags", Description = "Give your playing field a professional touch", Category = "Soccer", Price = 34.95m }, new Product { Name = "Stadium", Description = "Flat-packed 35,000-seat stadium", Category = "Soccer", Price = 79500 }, new Product { Name = "Thinking Cap", Description = "Improve brain efficiency by 75%", Category = "Chess", Price = 16 }, new Product { Name = "Unsteady Chair", Description = "Secretly give your opponent a disadvantage", Category = "Chess", Price = 29.95m }, new Product { Name = "Human Chess Board", Description = "A fun game for the family", Category = "Chess", Price = 75 }, new Product { Name = "Bling-Bling King", Description = "Gold-plated, diamond-studded King", Category = "Chess", Price = 1200 } ); context.SaveChanges(); } }
public void SavePermisionLog() { _dbcontext.SaveChanges(); }