Exemple #1
0
            public async Task <StatusAction> Handle(Command request, CancellationToken cancellationToken)
            {
                // handler logic
                try
                {
                    var course = new CourseDto
                    {
                        Id     = request.Id,
                        Name   = request.Name,
                        Title  = request.Title,
                        Photo  = request.Photo,
                        Price  = request.Price,
                        IsSale = request.IsSale,
                        ConditionRequirement = request.ConditionRequirement,
                        MainContent          = request.MainContent,
                        CustomerSegment      = request.CustomerSegment
                    };
                    course.CreateDate = request.CreateDate ?? DateTime.Now;

                    await services.UpdateAsync(course, course.Id);

                    return(new UpdateSuccess("khóa học"));
                }
                catch (Exception ex)
                {
                    if (ex.GetType() == typeof(NotFoundException))
                    {
                        throw new RestException(StatusCode.BadRequest, new { message = "Chủ đề khóa học không tồn tại" });
                    }
                    throw new RestException(StatusCode.BadRequest, new { message = "Cập nhật thất bại" });
                }
            }
Exemple #2
0
        public async Task <IHttpActionResult> Update([FromBody, CustomizeValidator(RuleSet = "default")] Course course)
        {
            if (course == null)
            {
                return(BadRequest());
            }
            var result = await _courseService.UpdateAsync(course);

            return(result.IsError ? BadRequest(result.Message) : (IHttpActionResult)Ok(result.Data));
        }