public void testUpdate() { // Arrange int count = repo.All().Count(); repo.Add(entity); this.repo.SaveChanges(); Assert.Null(repo.GetByName(n + "alala")); Assert.AreEqual(count + 1, repo.All().Count()); entity.Name += "alala"; // Act repo.Update(entity); repo.SaveChanges(); // Assert Assert.NotNull(repo.GetByName(n + "alala")); this.repo.HardDelete(entity); this.repo.SaveChanges(); }
/// <summary> /// /添加流程管理 /// </summary> /// <param name="model"></param> /// <returns></returns> public Result Add(Subject model) { if (model.SubjectRuleRangeList == null || model.SubjectStepFlowList == null) { return(new Result() { Succeed = false, Message = "参数错误!" }); } string msg = string.Empty; bool status = false; try { status = _repository.Add(model) > 0 ? true : false; } catch (Exception ex) { msg = ex.Message.ToString(); } var dataResult = new Result() { Succeed = status, Message = msg }; return(dataResult); }
public void Post([FromBody] Subject sub) { if (ModelState.IsValid) { subjectRepository.Add(sub); } }
private static bool MateriaAltaPruebas(string nameMateria, string nameTeacher) { ValidationResult <string> vrName; if (!(vrName = Subject.ValidateName(nameMateria)).IsSuccess) { Console.WriteLine(vrName.AllErrors); } ValidationResult <string> vrTeacher; if (!(vrTeacher = Subject.ValidateTeacher(nameTeacher)).IsSuccess) { Console.WriteLine(vrTeacher.AllErrors); } var subject = new Subject { Name = nameMateria, Teacher = nameTeacher }; var sr2 = SubjectRepository.Add(subject); if (sr2.IsSuccess && subject.Save().IsSuccess) { Console.WriteLine($"asignatura guardada correctamente"); return(true); } else { Console.WriteLine($"uno o más errores han ocurrido y la asignatura no se ha guardado correctamente"); } return(false); }
public ActionResult Create(SubjectModel model) { if (ModelState.IsValid) { // Map the view model to a domain model. var subject = Mapper.Map <Subject>(model); _subjectRepository.Add(subject); return(RedirectToAction("List")); } PrepareSubjectModel(model); return(View(model)); }
public JsonResult Add(SubjectViewModel subjectToAdd) { try { var validationResult = _subjectsViewModelValidator.Validate(subjectToAdd); if (!validationResult.IsValid) { return(Json(new { result = validationResult.Errors.Select(x => x.ErrorMessage).ToList() }, JsonRequestBehavior.AllowGet)); } var subject = Mapper.Map <Subject>(subjectToAdd); _subjectRepository.Add(subject); return(Json(new { result = "success" }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new { result = e.Message }, JsonRequestBehavior.AllowGet)); } }
public void Add(SubjectDM domain) { try { _SubjectRepo.Add(domain); } catch (Exception ex) { //Errors in this scope indicates system error (not validation errors) //If error not handled, log it and add system error if (!_GlobalErrors.ErrorHandled) { _Logger.Error(ex, "Database Error: Cannot Add Subject!"); _GlobalErrors.AddSystemError("Database Error: Cannot Add Subject!"); _GlobalErrors.ErrorHandled = true; } throw; } }
private static bool MateriaAlta() { LimpiarConsoleLine(); Console.WriteLine("3 - 1) Alta de Materia. Para volver al menú Materia en cualquier momento entra *."); Console.WriteLine("Entra el nombre de la materia:"); Console.WriteLine("Para volver sin guardar asignatura escriba *."); var name = ""; bool primera = true; ValidationResult <string> vrName = Subject.ValidateName(name); do { if (!primera) { Console.WriteLine(vrName.AllErrors); } name = Console.ReadLine(); if (name == "*") { return(false); } primera = false; } while (!(vrName = Subject.ValidateName(name)).IsSuccess); Console.WriteLine("escriba el nombre del profesor:"); var teacher = ""; primera = true; ValidationResult <string> vrTeacher = Subject.ValidateTeacher(teacher); do { if (!primera) { Console.WriteLine(vrTeacher.AllErrors); } teacher = Console.ReadLine(); if (teacher == "*") { return(false); } primera = false; } while (!(vrTeacher = Subject.ValidateName(teacher)).IsSuccess); var subject = new Subject { Name = name, Teacher = teacher }; var sr2 = SubjectRepository.Add(subject); if (sr2.IsSuccess && subject.Save().IsSuccess) { Console.WriteLine($"asignatura guardada correctamente"); return(true); } else { Console.WriteLine($"uno o más errores han ocurrido y la asignatura no se ha guardado correctamente"); } return(false); }