예제 #1
0
        public async Task <ApiResult> UpdateCourseAsync(TrainingCourseDTO courseDTO)
        {
            var result = default(ApiResult);
            var course = await courses.GetByIdAsync(courseDTO.Id);

            if (course == null)
            {
                var message       = "Course was not found";
                var loggerMessage = $"Course with title {courseDTO.Title} was not found";
                var errors        = new string[] { loggerMessage };
                result = ApiResult.GetErrorResult(ApiResultStatus.BadRequest, loggerMessage, message, errors);
            }
            else
            {
                var newCourse = mapperWrapper.MapEntity(courseDTO);
                newCourse.Cover = imageWorker.CutImageToName(newCourse.Cover);
                course          = await courses.UpdateAsync(course, newCourse);

                var model = mapperWrapper.MapModel(course);
                model.Cover = imageWorker.GetImageURL("courses", model.Cover);
                result      = ApiResult.GetOkResult(ApiResultStatus.Ok, data: model);
            }

            return(result);
        }
예제 #2
0
        public async Task <ApiResult> UpdateAccountAsync(AccountUpdateData accountUpdateData)
        {
            var result = default(ApiResult);
            var id     = accountUpdateData.User.Id;
            var user   = await users.GetByIdAsync(id);

            if (user == null)
            {
                var message       = "User was not found";
                var loggerMessage = $"User id = {id} was not found";
                var errors        = new string[] { message };
                result = ApiResult.GetErrorResult(ApiResultStatus.NotFound, loggerMessage, message, errors);
            }
            else
            {
                if (accountUpdateData.IsEmailChanged)
                {
                    await SendConfirmUpdateEmailMessageAsync(user, accountUpdateData.User.Email);
                }

                if (accountUpdateData.AnyFieldChanged)
                {
                    var newUser = mapperWrapper.MapEntity(accountUpdateData.User);

                    //user = UpdateHelper<SystemUser>.Update(context.Model, user, newUser);

                    user = await users.UpdateAsync(user, newUser);

                    //await context.SaveChangesAsync();
                }

                var data = await GetAccountData(user);

                result = ApiResult.GetOkResult(ApiResultStatus.Ok, data: data);
            }

            return(result);
        }