コード例 #1
0
        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());
            }
        }
コード例 #2
0
        public ActionResult AddCoach(CoachVm model)
        {
            if (ModelState.IsValid)
            {
                service.AddCoach(model);
                RedirectToAction("AllCoaches");
            }

            return(this.View(model));
        }
コード例 #3
0
        public async Task <IActionResult> CreateCoach([FromBody] CoachContract coach, CancellationToken cancellationToken)
        {
            var coachAdd = await _coachService.AddCoach(coach, cancellationToken);

            if (coachAdd)
            {
                return(Ok());
            }

            return(Conflict());
        }
コード例 #4
0
        public IActionResult Add(Coach coach)
        {
            EnsureCoachServiceInitialized();
            var response = _coachService.AddCoach(coach);

            if (IsErrorResponse(response, out var actionResult))
            {
                return(actionResult);
            }
            return(RedirectToAction(nameof(Index)));
        }
コード例 #5
0
 public ActionResult Create(CoachDTO coach)
 {
     try
     {
         service.AddCoach(coach);
     }
     catch
     {
         return(Content("\tERROR!\n\n\n Entered data is invalid!\n"));
     }
     return(RedirectToAction("Index"));
 }
コード例 #6
0
 /// <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));
     }
 }
コード例 #7
0
        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);
        }