public async Task <Response> Create(StudentCommentCreateModel studentCommentCreateModel, ClaimsPrincipal User) { using (var context = _applicationDbContextFactory.Create()) { User user = await UserManager.FindByNameAsync(User.Identity.Name); if (user != null) { var StudentComment = Mapper.Map <StudentComment>(studentCommentCreateModel); if (!context.Check <Student>(studentCommentCreateModel.StudentId)) { return new Response { Status = 500, Message = "Такого студента нет!" } } ; StudentComment.UserId = user.Id; StudentComment.CommentDateTime = DateTime.Now; context.StudentComments.Add(StudentComment); context.SaveChanges(); return(new Response { Status = 100, Message = "Запрос успешно прошел." }); } else { return(null); } } } }
public async Task <ActionResult <Response> > Create(StudentCommentCreateModel model) { return(await _StudentCommentService.Create(model, User)); }