Ejemplo n.º 1
0
        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 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 void AddCharacterToEvent(int characterId, int eventId)
        {
            var newCharacterEvent = new CharacterEvent
            {
                CharacterId = characterId,
                EventId     = eventId
            };

            _context.Add(newCharacterEvent);
            _context.SaveChanges();
        }