public async Task <IHttpActionResult> UpdateCourse(int courseId, [FromBody] Course model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (courseId != model.CourseId) { return(NotFound()); } db.Entry(model).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseExists(courseId)) { return(NotFound()); } else { throw; } } return(Ok(new ResponseMessage <Course> { Result = model })); }
public async Task <IHttpActionResult> UpdateStudent(int studentId, [FromBody] Student model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (studentId != model.StudentId) { return(BadRequest()); } db.Entry(model).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(studentId)) { return(NotFound()); } else { throw; } } return(Ok(new ResponseMessage <Student> { Result = model })); }
public ActionResult Edit([Bind(Include = "DepartmentId,Name")] Department department) { if (ModelState.IsValid) { db.Entry(department).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(department)); }
public ActionResult Edit([Bind(Include = "Id,Name,Gender,Contact,City,Experience,DepartmentId")] Worker worker) { if (ModelState.IsValid) { db.Entry(worker).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(worker)); }
public ActionResult Edit([Bind(Include = "StudentId,Name,RegNo,Address,HallName")] Student student) { if (ModelState.IsValid) { db.Entry(student).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public ActionResult Edit([Bind(Include = "SectionId,DepartmentId,Code,Description")] Section section) { if (ModelState.IsValid) { db.Entry(section).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Code", section.DepartmentId); return(View(section)); }
public ActionResult Edit([Bind(Include = "DepartmentId,Name,Location,StudentId,SectionId")] Department department) { if (ModelState.IsValid) { db.Entry(department).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StudentId = new SelectList(db.Students, "StudentId", "Name", department.StudentId); ViewBag.SectionId = new SelectList(db.Sections, "SectionId", "Name", department.SectionId); return(View(department)); }
public ActionResult Edit([Bind(Include = "SectionId,Name,StudentId")] Section section) { if (ModelState.IsValid) { db.Entry(section).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StudentId = new SelectList(db.Students, "StudentId", "Name", section.StudentId); return(View(section)); }
public async Task Consume(ConsumeContext <DeleteDepartmentRequest> context) { var department = _dbContext.Departments.FirstOrDefault(x => x.Id == context.Message.DepartmentId); if (department != null && department.EmployeeCount == 0) { _dbContext.Entry(department).State = EntityState.Deleted; await _dbContext.SaveChangesAsync(); await context.RespondAsync(new DeleteDepartmentResponse { DepartmentId = context.Message.DepartmentId, IsDeleted = true }); } await context.RespondAsync(new DeleteDepartmentResponse { DepartmentId = context.Message.DepartmentId, IsDeleted = false }); }
public async Task <IHttpActionResult> UpdateInvoice(int invoiceId, [FromBody] Invoice model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (invoiceId != model.InvoiceId) { return(BadRequest()); } var existinginvoice = db.Invoices .Where(p => p.InvoiceId == model.InvoiceId) .Include(p => p.InvoiceDetails) .SingleOrDefault(); if (existinginvoice != null) { // Update Invoice db.Entry(existinginvoice).CurrentValues.SetValues(model); foreach (var InvoiceDetail in existinginvoice.InvoiceDetails.ToList()) { if (!model.InvoiceDetails.Any(x => x.InvoiceDetailsId == InvoiceDetail.InvoiceDetailsId)) { db.InvoiceDetails.Remove(InvoiceDetail); db.SaveChanges(); } } foreach (var invoicedetail in model.InvoiceDetails) { var existingInvoiceDetail = existinginvoice.InvoiceDetails .Where(c => c.InvoiceDetailsId == invoicedetail.InvoiceDetailsId) .SingleOrDefault(); if (existingInvoiceDetail != null) { // Update InvoiceDetails db.Entry(existingInvoiceDetail).CurrentValues.SetValues(invoicedetail); } else { existinginvoice.InvoiceDetails.Add(invoicedetail); } db.SaveChanges(); } } try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InvoiceExits(invoiceId)) { return(NotFound()); } else { throw; } } return(Ok(new ResponseMessage <Invoice> { Result = model })); }