public void Update(CompetitionViewModel c, int discId, int placeId)
        {
            Competition comp = null;

            if (c.Id == 0)
            {
                comp = new Competition {
                };

                _context.Competitions.Add(comp);
            }
            else
            {
                comp = _context.Competitions.FirstOrDefault(x => x.Id == c.Id);
            }

            var place      = _context.Places.FirstOrDefault(x => x.Id == placeId);
            var discipline = _context.Disciplines.FirstOrDefault(x => x.Id == discId);

            comp.Name = c.Name;

            if (place != null)
            {
                comp.PlaceId = place.Id;
            }
            else
            {
                comp.PlaceId = 1;
            }


            if (discipline != null)
            {
                comp.DisciplineId = discipline.Id;
            }
            else
            {
                comp.DisciplineId = 1;
            }

            comp.DateStart     = c.DateStart;
            comp.DateEnded     = c.DateEnded;
            comp.DateCanceled  = c.DateCanceled;
            comp.IsCanceled    = c.IsCanceled;
            comp.IsStarted     = c.IsStarted;
            comp.MaxUsersCount = c.MaxUsersCount;
            comp.Prize         = c.Prize;
            comp.CreatorId     = c.CreatorId;


            _context.SaveChanges();
        }
Exemple #2
0
        public User Create(string login, string password)
        {
            var user = new User {
                Login = login, Password = password
            };

            _context.Users.Add(user);
            _context.SaveChanges();
            return(user);
        }