コード例 #1
0
        public IActionResult UpdateCourse([FromBody] TrainingCourse trainingCourse)
        {
            var lang          = Request.Headers["language"].ToString();
            var errorMessages = new List <string>();

            try
            {
                var course = _trainingCourseRepository.FindById(trainingCourse.Id);
                if (course == null)
                {
                    return(NotFound());
                }

                course.Name          = trainingCourse.Name;
                course.CourseUrl     = trainingCourse.CourseUrl;
                course.Type          = trainingCourse.Type;
                course.Establishment = trainingCourse.Establishment;
                course.Duration      = trainingCourse.Duration;
                course.DateTime      = trainingCourse.DateTime;
                course.Country_EN    = trainingCourse.Country_EN;
                course.Country_FR    = !string.IsNullOrEmpty(trainingCourse.Country_FR) ? trainingCourse.Country_FR : trainingCourse.Country_EN;
                course.City_EN       = trainingCourse.City_EN;
                course.City_FR       = !string.IsNullOrEmpty(trainingCourse.City_FR) ? trainingCourse.City_FR : trainingCourse.City_EN;


                var updatedCourse = _trainingCourseRepository.Update(course);

                return(Ok(new { updatedCourse }));
            }
            catch
            {
                errorMessages.Add(_translator.GetTranslation("ERROR", lang));
                return(BadRequest(new { errors = errorMessages }));
            }
        }
コード例 #2
0
        public ActionResult <CommonResponeModel> Update(TrainingCourseUpdateRequestModel model)
        {
            var databaseObject = model.MapTo <TrainingCourse>();

            databaseObject.InitBeforeSave(RequestUsername, InitType.Create);
            int result = trainingCourseRepository.Update(databaseObject);

            if (result > 0)
            {
                Result = new SuccessResultFactory().Factory(ActionType.Edit);
            }
            else
            {
                Result = new ErrorResultFactory().Factory(ActionType.Edit);
            }

            return(GetCommonRespone());
        }