public IActionResult CreationPlaceOfWork([FromBody] PlaceOfWork placeOfWork) { if (placeOfWork == null) { return(BadRequest()); } db.Add(placeOfWork); db.SaveChanges(); return(Ok()); }
public async Task <IActionResult> Edit(int id, int cathedraId, [Bind("Id,DateOfStartWork,DateOfEndWork")] PlaceOfWork placeOfWork) { placeOfWork.CathedraId = cathedraId; if (id != placeOfWork.Id) { return(NotFound()); } if (ModelState.IsValid) { DateTime time = DateTime.Now; DateTime time1 = placeOfWork.DateOfStartWork; DateTime time2 = placeOfWork.DateOfEndWork.Value; if (DateTime.Compare(time, time1) <= 0) { ViewData["CathedraId"] = cathedraId; ModelState.AddModelError("DateOfStartWork", "DateOfStartWork error"); return(View(placeOfWork)); } if (DateTime.Compare(time, time2) <= 0) { ViewData["CathedraId"] = cathedraId; ModelState.AddModelError("DateOfEndWork", "DateOfEndWork error"); return(View(placeOfWork)); } if (DateTime.Compare(time2, time1) <= 0) { ViewData["CathedraId"] = cathedraId; ModelState.AddModelError("DateOfEndWork", "DateOfEndWork error"); return(View(placeOfWork)); } try { _context.Update(placeOfWork); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlaceOfWorkExists(placeOfWork.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index", "PlaceOfWorks", new { id = cathedraId, name = _context.Cathedra.Where(c => c.Id == cathedraId).FirstOrDefault().CathedraName })); } ViewData["CathedraId"] = new SelectList(_context.Cathedra, "Id", "CathedraName", placeOfWork.CathedraId); return(RedirectToAction("Index", "PlaceOfWorks", new { id = cathedraId, name = _context.Cathedra.Where(c => c.Id == cathedraId).FirstOrDefault().CathedraName })); }
public async Task <IActionResult> Create(int cathedraId, [Bind("Id,CathedraId,DateOfStartWork,DateOfEndWork")] PlaceOfWork placeOfWork) { placeOfWork.CathedraId = cathedraId; // ViewBag.CathedraId = cathedraId; if (ModelState.IsValid) { DateTime time = DateTime.Now; DateTime time1 = placeOfWork.DateOfStartWork; DateTime time2 = placeOfWork.DateOfEndWork.Value; if (DateTime.Compare(time, time1) <= 0) { ViewData["CathedraId"] = cathedraId; ModelState.AddModelError("DateOfStartWork", "DateOfStartWork error"); return(View(placeOfWork)); } if (DateTime.Compare(time, time2) <= 0) { ViewData["CathedraId"] = cathedraId; ModelState.AddModelError("DateOfEndWork", "DateOfEndWork error"); return(View(placeOfWork)); } if (DateTime.Compare(time2, time1) <= 0) { ViewData["CathedraId"] = cathedraId; ModelState.AddModelError("DateOfEndWork", "DateOfEndWork error"); return(View(placeOfWork)); } _context.Add(placeOfWork); await _context.SaveChangesAsync(); //return RedirectToAction(nameof(Index)); return(RedirectToAction("Index", "PlaceOfWorks", new { id = cathedraId, name = _context.Cathedra.Where(c => c.Id == cathedraId).FirstOrDefault().CathedraName })); } return(RedirectToAction("Index", "PlaceOfWorks", new { id = cathedraId, name = _context.Cathedra.Where(c => c.Id == cathedraId).FirstOrDefault().CathedraName })); }