public async Task <IHttpActionResult> Put(MemoryDTO memoryDTO, int id) { if (ModelState.IsValid) { return(BadRequest(ModelState)); } if (memoryDTO.Id != id) { return(BadRequest(ModelState)); } var flag = await memoryService.GetById(id); if (flag == null) { return(NotFound()); } try { var memory = mapper.Map <Memory>(memoryDTO); memory = await memoryService.Insert(memory); return(Ok(memory)); } catch (Exception e) { return(InternalServerError(e)); } }
public async Task <IHttpActionResult> Post(MemoryDTO memoryDTO) { if (ModelState.IsValid) { return(BadRequest(ModelState)); } try { var memory = mapper.Map <Memory>(memoryDTO); memory = await memoryService.Insert(memory); return(Ok(memory)); } catch (Exception e) { return(InternalServerError(e)); } }
public ActionResult <MemoryDTO> GetMemory(int id) { Memory memory = _memoryRepository.GetById(id); if (memory == null) { return(NotFound()); } List <User> users = new List <User>(); if (memory.Members != null) { memory.Members.ForEach(mem => users.Add(_userRepository.GetById(mem.UserId))); } MemoryDTO result = new MemoryDTO(memory.MemoryId, memory.Title, memory.SubTitle, memory.StartDate, memory.EndDate, memory.Location, users, memory.Photos); return(result); }