public Event UpdateOrCreateEvent([FromBody] Event lfEvent) { Event eventToUpdate = null; var lfEventStartTime = lfEvent.StartDate.TimeOfDay; lfEvent.StartDate = lfEvent.StartDate.Subtract(lfEventStartTime); var lfEventEndTime = lfEvent.EndDate.TimeOfDay; lfEvent.EndDate = lfEvent.EndDate.Subtract(lfEventEndTime); if (lfEvent.Id != 0) { eventToUpdate = _context.tblEvent.FirstOrDefault(e => e.Id == lfEvent.Id); } if (eventToUpdate != null) { _context.Entry(eventToUpdate).CurrentValues.SetValues(lfEvent); } else { _context.Add(lfEvent); } _context.SaveChanges(); return(lfEvent); }
public Character UpdateOrCreateCharacter(Character character) { Character characterToUpdate = null; if (character.Id != 0) { characterToUpdate = _context.tblCharacter.Include(s => s.Skills).FirstOrDefault(c => c.Id == character.Id); } if (characterToUpdate != null) { foreach (var skill in characterToUpdate.Skills) { _context.tblCharacterSkills.Remove(skill); } _context.Entry(characterToUpdate).CurrentValues.SetValues(character); } else { _context.Add(character); } _context.tblCharacterSkills.AddRange(character.Skills); _context.SaveChanges(); return(character); }
public IActionResult UpdateCharacterEventDetails([FromBody] CharacterEvent characterEvent) { var characterEventToUpdate = _context.tblCharacterEvents.FirstOrDefault(ce => ce.Id == characterEvent.Id); _context.Entry(characterEventToUpdate).CurrentValues.SetValues(characterEvent); _context.SaveChanges(); return(Ok()); }