Exemplo n.º 1
0
        public ActionResult <PayloadResponse> EditTestAthlete([FromBody] TestAthleteListViewModel info)
        {
            PayloadResponse response = new PayloadResponse();

            response.RequestTime = DateTime.Now.ToString();

            TestAthlete athlete = _repo.TestAthleteRepository.GetAll().Where(x => x.ID == info.ID && !x.IsRemoved).FirstOrDefault();

            if (info == null && info.ID <= 0)
            {
                response.Message      = "Data did not send properly";
                response.Payload      = athlete;
                response.PayloadType  = "EditTestAthlete";
                response.ResponseTime = DateTime.Now.ToString();
                response.Success      = false;
                return(response);
            }
            athlete.TestValue       = info.Distance;
            athlete.UpdatedBy       = Convert.ToInt32(User.Identity.Name);
            athlete.UpdatedDate     = DateTime.Now;
            athlete.FitnessRatingID = _repo.TestCustomRepository.GetFitnessRatingID(info.Distance);
            _repo.TestAthleteRepository.Update(athlete);

            _repo.Save();

            response.Message      = "Athlete is successfully updated.";
            response.Payload      = null;
            response.PayloadType  = "EditTestAthlete";
            response.ResponseTime = DateTime.Now.ToString();
            response.Success      = true;
            return(response);
        }
Exemplo n.º 2
0
        public ActionResult DeleteAthlete([FromBody] TestAthleteListViewModel info)
        {
            TestAthlete athlete = _repo.TestAthleteRepository.GetAll().Where(x => x.ID == info.ID && !x.IsRemoved).FirstOrDefault();

            if (info == null && info.ID <= 0)
            {
                return(BadRequest());
            }
            athlete.IsRemoved = true;
            _repo.TestAthleteRepository.Update(athlete);
            _repo.Save();
            info.AthleteID = athlete.ID;
            info.ID        = athlete.ID;
            return(Ok(info));
        }
Exemplo n.º 3
0
        public ActionResult <PayloadResponse> CreateTestAthlete([FromBody] TestAthleteViewModel info)
        {
            PayloadResponse response    = new PayloadResponse();
            TestAthlete     testAthlete = new TestAthlete();

            if (info == null)
            {
                response.Message      = "Data did not send properly";
                response.Payload      = testAthlete;
                response.PayloadType  = "CreateTestAthlete";
                response.ResponseTime = DateTime.Now.ToString();
                response.Success      = false;
                return(response);
            }

            TestAthlete existingTest = _repo.TestCustomRepository.GetTestAthleteByTestAndAthlete(info.ID, info.AthleteID);

            if (existingTest != null && existingTest.ID > 0)
            {
                response.Message      = string.Format("The Athlete ({0} {1}) is already exist into the Test. ", existingTest.Athlete.FirstName, existingTest.Athlete.LastName);
                response.Payload      = testAthlete;
                response.PayloadType  = "CreateTestAthlete";
                response.ResponseTime = DateTime.Now.ToString();
                response.Success      = false;
                return(response);
            }

            testAthlete.AthleteID       = info.AthleteID;
            testAthlete.TestValue       = info.TestValue;
            testAthlete.TestID          = info.ID;
            testAthlete.CreatedBy       = Convert.ToInt32(User.Identity.Name);
            testAthlete.CreatedDate     = DateTime.Now;
            testAthlete.IsRemoved       = false;
            testAthlete.FitnessRatingID = _repo.TestCustomRepository.GetFitnessRatingID(testAthlete.TestValue);
            _repo.TestAthleteRepository.Add(testAthlete);
            _repo.Save();

            response.Message      = "Athlete is successfully added in Test.";
            response.Payload      = null;
            response.PayloadType  = "CreateTestAthlete";
            response.ResponseTime = DateTime.Now.ToString();
            response.Success      = true;
            return(response);
        }