コード例 #1
0
        public NegativeGameEvent Update(int id, NegativeGameEvent gameEvent)
        {
            if (Find().Count(i => i.Name == gameEvent.Name) > 1)
            {
                Console.Write(gameEvent.Name + " is already in the db!");

                return(gameEvent);
            }
            else
            {
                var dbEvent = Get(id);
                if (dbEvent != null)
                {
                    dbEvent.Name        = gameEvent.Name;
                    dbEvent.Description = gameEvent.Description;
                    dbEvent.DefenseWithGearDescription    = gameEvent.DefenseWithGearDescription;
                    dbEvent.DefenseWithoutGearDescription = gameEvent.DefenseWithoutGearDescription;
                    dbEvent.DefenseLoss = gameEvent.DefenseLoss;
                    dbEvent.Probability = gameEvent.Probability;

                    _database.NegativeGameEvents.Update(dbEvent);
                    _database.SaveChanges();
                }
            }

            return(gameEvent);
        }
コード例 #2
0
        public IActionResult EditNegative(NegativeGameEvent gameEvent)
        {
            if (gameEvent != null)
            {
                _negativeGameEventService.Update(gameEvent.Id, gameEvent);
            }

            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public NegativeGameEvent Create(NegativeGameEvent gameEvent)
        {
            //check if event already is in db
            var searchEvent = _database.NegativeGameEvents.SingleOrDefault(p => p.Name == gameEvent.Name);

            if (searchEvent != null)
            {
                Console.Write(gameEvent.Name + " is already in the db!");

                //return same object
                return(gameEvent);
            }
            else
            {
                //save in db
                _database.NegativeGameEvents.Add(gameEvent);
                _database.SaveChanges();
                Console.Write("New event added to db: " + gameEvent.Name + ". ");

                //return the new event
                return(gameEvent);
            }
        }