public async Task <ActionResult <Reservation> > Put(int id, [FromForm] Reservation reservation) { if (id != reservation.Id) { return(BadRequest()); } _context.Entry(reservation).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReservationsExist(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Contact> > Put(int id, [FromBody] Contact contact) { if (id != contact.Id) { return(BadRequest()); } _context.Entry(contact).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExist(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutContactType(int id, ContactType contactType) { if (id != contactType.Id) { return(BadRequest()); } _context.Entry(contactType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactTypeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit([Bind(Include = "Id,Name,RoomType,NumberOfPersons,CheckInDate,CheckOutDate")] Reservation reservation) { if (ModelState.IsValid) { db.Entry(reservation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(reservation)); }
public IActionResult Detail() { string id, phone; if (TempData.ContainsKey("id") && TempData.ContainsKey("phone")) { id = TempData["id"] as string; phone = TempData["phone"] as string; } else { GetSessionTicket(out id, out phone); } ReservationDetail _detail = VerifyReservationDetail(id, phone); if (_detail == null) { return(RedirectToAction(nameof(Index))); } db.Entry(_detail).EnsureReferencesLoaded(true); if (_detail.ReservationBoardMessages.Count > 0) { List <ReservationBoardMessage> msgs = _detail.ReservationBoardMessages.Where(msg => msg.IsPublic == true).OrderByDescending(msg => msg.PostedTime).Take(5).ToList(); foreach (var msg in msgs) { db.Entry(msg).EnsureReferencesLoaded(false); } ViewData["BoardMessages"] = msgs; } else { ViewData["BoardMessages"] = new List <ReservationBoardMessage>(); } // 超期自动关闭 if (_detail.State == ReservationState.Cancelled && (DateTimeHelper.GetBeijingTime() - _detail.ActionDate) > cancelClosedTimeout) { _detail.State = ReservationState.ClosedWithoutComplete; _detail.ActionDate = _detail.ActionDate + cancelClosedTimeout; EntityEntry <ReservationDetail> entry = db.Entry(_detail); entry.State = EntityState.Modified; db.SaveChanges(); entry.Reload(); _detail = entry.Entity; } ViewData["token"] = EncryptDetailCredential(_detail); ViewData["actionCode"] = ACTION_CODES; if (TempData.ContainsKey("showhint")) { TempData.Remove("showhint"); ViewData["ShowHint"] = true; } else { ViewData["ShowHint"] = false; } SetSessionTicket(id, phone); return(View(_detail)); }
public void Save(Order order) { _context.Entry(order).State = System.Data.Entity.EntityState.Detached; _context.SaveChanges(); }
public IActionResult ViewDetails(int id = -1, string filter = "uncompleted", int page = 1) { DutyMember member = VerifyDutyMemberLogIn(); if (member == null) { return(RedirectToAction(nameof(Index))); } ViewData["Member"] = member; var details = from detail in db.ReservationDetails select detail; int index = 0; DateTime now = DateTimeHelper.GetBeijingTime(); bool showColor = false; switch (filter) { case "uncompleted": index = 0; details = details.Where(detail => detail.ReservationDate >= now && (detail.State == ReservationState.Answered || detail.State == ReservationState.Cancelled || detail.State == ReservationState.NewlyCreated)); break; case "me": details = details.Where(detail => detail.DutyMember == member).OrderBy(detail => detail.ReservationDate); index = 1; break; case "closed": details = details.Where(detail => detail.State == ReservationState.ClosedWithoutComplete).OrderByDescending(detail => detail.ActionDate); index = 2; break; case "completed": details = details.Where(detail => detail.State == ReservationState.Completed).OrderByDescending(detail => detail.ActionDate); index = 3; break; case "all": default: index = 4; details = details.OrderBy(detail => detail.ReservationDate); showColor = true; break; } ViewData["Filter"] = index; ViewData["ShowColor"] = showColor; int total = details.Count(); int maxpage = (int)Math.Ceiling(total * 1.0 / ITEMS_PER_PAGE); if (maxpage <= 0) { maxpage = 1; } if (page >= maxpage) { page = maxpage; } page--; if (page < 0) { page = 0; } details = details.Skip(page * ITEMS_PER_PAGE).Take(ITEMS_PER_PAGE); if (id == -1) { ViewData["Current"] = null; ViewData["Token"] = GetDutyMemberDetailToken(member, "-1"); } else { ReservationDetail current = (from detail in db.ReservationDetails where detail.Id == id select detail).FirstOrDefault(); if (current == null) { return(RedirectToAction(nameof(ViewDetails), new { filter = filter, page = page })); } db.Entry(current).EnsureReferencesLoaded(true); IEnumerable <ReservationBoardMessage> messages = current.ReservationBoardMessages.OrderByDescending(item => item.PostedTime).Take(5); foreach (ReservationBoardMessage msg in messages) { db.Entry(msg).EnsureReferencesLoaded(false); } ViewData["Messages"] = messages; ViewData["Current"] = current; ViewData["Token"] = GetDutyMemberDetailToken(member, current.Id.ToString()); } if (details.Count() > 0) { List <ReservationDetail> detaillist = details.ToList(); foreach (ReservationDetail detail in detaillist) { db.Entry(detail).EnsureReferencesLoaded(false); } ViewData["Details"] = detaillist; } else { ViewData["Details"] = new List <ReservationDetail>(); } ViewData["ShowMore"] = page < (maxpage - 1); return(View()); }