Пример #1
0
        public async Task <ResponseModel> UpdateProfileAsync(Guid id, StudentUpdateProfileModel studentUpdateProfileModel)
        {
            var student = await GetAll().FirstOrDefaultAsync(x => x.Id == id);

            if (student == null)
            {
                return(new ResponseModel()
                {
                    StatusCode = System.Net.HttpStatusCode.NotFound,
                    Message = "User is not exist. Please try again!"
                });
            }
            else
            {
                //await _userInRoleRepository.DeleteAsync(user.UserInRoles);

                //var userInRoles = new List<UserInRole>();
                //foreach (var roleId in userUpdateProfileModel.RoleIds)
                //{
                //    userInRoles.Add(new UserInRole()
                //    {
                //        UserId = user.Id,
                //        RoleId = roleId
                //    });
                //}

                //_userInRoleRepository.GetDbContext().UserInRoles.AddRange(userInRoles);
                //await _userInRoleRepository.GetDbContext().SaveChangesAsync();

                studentUpdateProfileModel.SetUserModel(student);
                await _studentRepository.UpdateAsync(student);

                student = await GetAll().FirstOrDefaultAsync(x => x.Id == id);

                return(new ResponseModel
                {
                    StatusCode = System.Net.HttpStatusCode.OK,
                    Data = new StudentViewModel(student)
                });
            }
        }
        //[CustomAuthorize]
        public async Task <IActionResult> Put(Guid id, [FromBody] StudentUpdateProfileModel studentUpdateProfileModel)
        {
            var responseModel = await _studentService.UpdateProfileAsync(id, studentUpdateProfileModel);

            return(new CustomActionResult(responseModel));
        }