public IActionResult Put(Guid id, [FromBody] HomeworkModel model) { try { var homework = homeworks.Update(id, HomeworkModel.ToEntity(model)); return(CreatedAtRoute("Get", new { id = homework.Id }, HomeworkModel.ToModel(homework))); } catch (ArgumentException e) { return(BadRequest(e.Message)); } }
public ActionResult Edit(HomeworkModel model, FormCollection frm, bool continueEditing) { if (!_permissionService.Authorize("ManageHomework")) { return(AccessDeniedView()); } var user = _userContext.CurrentUser; // Check for duplicate classroom, if any var checkHomework = _smsService.CheckHomeworkExists(model.Name, model.Id); if (checkHomework) { ModelState.AddModelError("Name", "A Homework with the same name already exists. Please choose a different name."); } if (ModelState.IsValid) { var objHomework = _smsService.GetHomeworkById(model.Id); if (objHomework != null) { model.CreatedOn = objHomework.CreatedOn; objHomework = model.ToEntity(objHomework); objHomework.ModifiedOn = DateTime.Now; _smsService.UpdateHomework(objHomework); } } else { model.AvailableAcadmicYears = _smsService.GetAllAcadmicYears().Select(x => new SelectListItem() { Text = x.Name.Trim(), Value = x.Id.ToString(), Selected = model.AcadmicYearId == x.Id }).ToList(); return(View(model)); } SuccessNotification("Homework updated successfully."); if (continueEditing) { return(RedirectToAction("Edit", new { id = model.Id })); } return(RedirectToAction("List")); }
public void GetHomeworkTest() { var homeworkModel = new HomeworkModel { Id = Guid.NewGuid(), Description = "A basic homework", }; var mock = new Mock <IHomeworkLogic>(MockBehavior.Strict); mock.Setup(m => m.Get(homeworkModel.Id)).Returns(homeworkModel.ToEntity()); var controller = new HomeworksController(mock.Object); var result = controller.Get(homeworkModel.Id); var createdResult = result as OkObjectResult; var model = createdResult.Value as HomeworkModel; mock.VerifyAll(); Assert.AreEqual(homeworkModel.Description, model.Description); Assert.AreEqual(homeworkModel.Id, model.Id); }