public ActionResult <bool> AddMailind(HomeGroupViewModel homeGroup) { if (ModelState.IsValid) { var response = new { isSuccess = true, id = _groupService.InsertHomeGroup(_mapper.Map <HomeGroup>(homeGroup))?.Id }; return(Ok(response)); } return(BadRequest(ModelState)); }
public ActionResult <bool> Update(int id, [FromBody] HomeGroupViewModel model) { var homeGroups = _groupService.GetHomeGroup(id); if (homeGroups == null) { return(BadRequest("Таку домашню групу не знайдено")); } if (ModelState.IsValid) { homeGroups.Name = model.Name; return(Ok(_groupService.UpdateHomeGroup(homeGroups))); } return(BadRequest(ModelState)); }
public async Task <IActionResult> Index() { ApplicationUser appUser = await _userManager.GetUserAsync(HttpContext.User); User user = _repository.GetUser(Guid.Parse(appUser.Id)); HomeGroupViewModel model = new HomeGroupViewModel(); if (user.ActiveGroup == null) { model.AnyActive = false; return(View(model)); } model.AnyActive = true; model.Name = user.ActiveGroup.Name; List <Post> posts = _repository.GetPosts(user.ActiveGroup.Id); if (posts != null) { model.Posts = posts.Select(post => new IndexPostViewModel() { Id = post.Id.ToString(), Text = post.Text, Title = post.Title, TimePosted = post.CreatedOn, TimeModified = post.ModifiedOn, User = post.User.Id.ToString(), Event = post.Event?.Name, CurrentUserCanEdit = post.User == user }).ToList(); } else { model.Posts = new List <IndexPostViewModel>(); } return(View(model)); }