private void AddCoach() { PrintSpecial(Label("ADD COACH")); try { Coach coach = new Coach(); Print("Name:"); coach.Name = Console.ReadLine(); Print(""); Print("Age:"); coach.Age = int.Parse(Console.ReadLine()); Print(""); coachService.AddCoach(coach); Print("Coach added successfully!"); } catch (ArgumentException e) { Print(e.Message); } catch (Exception) { Print(SomethingWentWrong()); } }
public ActionResult AddCoach(CoachVm model) { if (ModelState.IsValid) { service.AddCoach(model); RedirectToAction("AllCoaches"); } return(this.View(model)); }
public async Task <IActionResult> CreateCoach([FromBody] CoachContract coach, CancellationToken cancellationToken) { var coachAdd = await _coachService.AddCoach(coach, cancellationToken); if (coachAdd) { return(Ok()); } return(Conflict()); }
public IActionResult Add(Coach coach) { EnsureCoachServiceInitialized(); var response = _coachService.AddCoach(coach); if (IsErrorResponse(response, out var actionResult)) { return(actionResult); } return(RedirectToAction(nameof(Index))); }
public ActionResult Create(CoachDTO coach) { try { service.AddCoach(coach); } catch { return(Content("\tERROR!\n\n\n Entered data is invalid!\n")); } return(RedirectToAction("Index")); }
/// <summary> /// 新增 /// </summary> /// <param name="entity"></param> /// <returns></returns> public JsonResult Add(Coach entity) { ModelState.Remove("ID"); ModelState.Remove("CreatedTime"); ModelState.Remove("UpdatedTime"); ModelState.Remove("IsDelete"); if (ModelState.IsValid) { var result = ICoachService.AddCoach(entity); return(JResult(result)); } else { return(ParamsErrorJResult(ModelState)); } }
public async Task Add_Coach() { Setup(); var coaches = GenerateListOfCoches(); var newCoach = new CoachContract() { DateBirth = "01.02.2000", Description = "TestDesc", FirstName = "Denis", LastName = "Denisovich", Id = 0, PhoneNumber = "+380145674584" }; _applicationContextMock.Setup(x => x.Coaches).ReturnsDbSet(coaches); _testedService = new CoachService(Logger, _applicationContextMock.Object); var result = (await _testedService.AddCoach(newCoach, CancellationToken.None)); Assert.True(result); }