public async Task Update(string id, SocialListVM listVM) { var list = _repo.Get(id); if (list == null) { await Create(listVM); } else { var updatedList = _mapper.Map <SocialList>(listVM); var updateTask = _repo.UpdateAsync(id, updatedList); // Update the list details if name has changed if (list.Name != listVM.Name) { var details = _repo.GetListsDetails(); var listDetails = details.Lists.Find(l => l.Id == id); listDetails.Name = listVM.Name; await _repo.UpdateListsDetailsAsync(details.Id, details); } await updateTask; } }
public async Task <IActionResult> UpdateSocialList(string id, SocialListVM doc) { if (id != doc.Id) { return(BadRequest(new ErrorResponse(400, "Ids do not match"))); } await _manager.Update(id, doc); return(NoContent()); }
public async Task <SocialListVM> Create(SocialListVM listVM) { listVM.Created = DateTime.UtcNow; var list = _mapper.Map <SocialList>(listVM); var createTask = _repo.CreateAsync(list); // Also add the new details into the listDetails var details = _repo.GetListsDetails(); await createTask; details.Lists.Add(_mapper.Map <SocialListBase>(list)); await _repo.UpdateListsDetailsAsync(details.Id, details); listVM.Id = list.Id; return(listVM); }
public async Task UpdateAndPublish(string id, SocialListVM listVM) { await Update(id, listVM); _xal.PublishList(_mapper.Map <SocialList>(listVM)); }
public async Task <ActionResult <SocialListVM> > CreateSocialList(SocialListVM doc) { await _manager.Create(doc); return(CreatedAtAction(nameof(GetSocialList), new { id = doc.Id }, doc)); }