Example #1
0
 public static GetInstructorByIdRequest ConvertInstructorId(this UpdateInstructorDataRequest request)
 {
     return(new GetInstructorByIdRequest
     {
         InstructorId = request.Id
     });
 }
Example #2
0
 public static InstructorData ConvertToInstructorData(this UpdateInstructorDataRequest request)
 {
     return(new InstructorData
     {
         Id = request.Id,
         FullName = request.FullName,
         Email = request.Email,
         Bio = request.Bio,
         Language = request.Language
     });
 }
        public HttpResponseMessage UpdateInstructorData([FromBody] UpdateInstructorDataRequest request)
        {
            var response = _service.UpdateInstructor(request);

            if (response)
            {
                return(Request.CreateResponse <bool>(HttpStatusCode.OK, response));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Failed to update instructor data"));
            }
        }
Example #4
0
        public void UpdateInstructorDataUnHappy()
        {
            var request = new UpdateInstructorDataRequest
            {
                Id       = 1112,
                FullName = "Tommy Leins",
                Email    = "*****@*****.**",
                Bio      = "Senior Andoid Developer",
                Language = "Kotlin"
            };

            var ex = Xunit.Assert.Throws <Exception>(() => service.UpdateInstructorData(request));

            Xunit.Assert.Equal("Instructor does not exist", ex.Message);
        }
Example #5
0
        public void UpdateInstructorData()
        {
            var request = new UpdateInstructorDataRequest()
            {
                Id       = 12,
                FullName = "Tommy Leins",
                Email    = "*****@*****.**",
                Bio      = "Senior Andoid Developer/Java Developer",
                Language = "Kotlin"
            };

            var res = service.UpdateInstructorData(request);

            Xunit.Assert.True(res);
        }
        public bool UpdateInstructorData(UpdateInstructorDataRequest request)
        {
            string sql = @"UPDATE Instructor SET FullName = @FullName, Email = @Email,Bio = @Bio ,Language = @Language WHERE Id = @Id ";
            int    result;
            var    parameters = new { request.Id, request.FullName, request.Email, request.Bio, request.Language };

            using (var con = GetSqlConnection())
            {
                using (var transaction = con.BeginTransaction())
                {
                    if (GetInstructorById(request.ConvertInstructorId()).Instructor != null)
                    {
                        result = con.Execute(sql, parameters, transaction: transaction);
                    }
                    else
                    {
                        throw new Exception("Instructor does not exist");
                    }
                    transaction.Commit();
                }
            }
            return(result == 1);
        }
Example #7
0
        public bool UpdateInstructor(UpdateInstructorDataRequest request)
        {
            ValidateUserData(request.ConvertToInstructorData());

            return(_dbService.UpdateInstructorData(request));
        }