Пример #1
0
        public static Sport GetOrCreate(string name)
        {
            try
            {
                validateName(name);

                Sport sport;
                using (var db = new MyDbContext())
                {
                    sport = db.Sport.Where(p => p.Name == name).FirstOrDefault();

                    if (sport == null)
                    {
                        sport = new Sport();
                        sport.Name = name;
                        db.Sport.Add(sport);
                        db.SaveChanges();
                    }

                    return sport;
                }
            }
            catch (Exception e)
            {
                throw new DomainException("Could not find or create sport", e);
            }
        }
 public static void Add(JoinedUser joinedUser)
 {
     try
     {
         using (var db = new MyDbContext())
         {
             db.JoinedUser.Add(joinedUser);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw new DomainException("Could not add joined user", e);
     }
 }
Пример #3
0
 public static void Register(User user)
 {
     try
     {
         using (var db = new MyDbContext())
         {
             db.User.Add(user);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw new DomainException("Could not create user", e);
     }
 }
 public static void Create(Suggestion suggestion)
 {
     try
     {
         using (var db = new MyDbContext())
         {
             db.JoinedUser.Add(suggestion.JoinedUsers[0]);
             db.Suggestion.Add(suggestion);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw new DomainException("Could not create suggestion", e);
     }
 }
 public static void Update(Suggestion updatedSuggestion)
 {
     try
     {
         using (var db = new MyDbContext())
         {
             var suggestion = db.Suggestion.Single((i => i.Id == updatedSuggestion.Id));
             updatedSuggestion.CreatorId = suggestion.CreatorId;
             db.Entry(suggestion).CurrentValues.SetValues(updatedSuggestion);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw new DomainException("Could not update suggestion", e);
     }
 }
Пример #6
0
        public static void Update(User newUser)
        {
            try
            {
                using (var db = new MyDbContext())
                {
                    User dbUser = db.User.Single(i => i.Id == newUser.Id);
                    dbUser.Area = newUser.Area;
                    dbUser.BirthDate = newUser.BirthDate;
                    dbUser.FirstName = newUser.FirstName;
                    dbUser.Gender = newUser.Gender;
                    dbUser.LastName = newUser.LastName;
                    dbUser.PhoneNumber = newUser.PhoneNumber;
                    dbUser.State = newUser.State;
                    dbUser.StreetAddress = newUser.StreetAddress;
                    dbUser.Password = newUser.Password;
                    db.SaveChanges();

                }
            }
            catch (Exception e)
            {
                throw new DomainException("Could not update user", e);
            }
        }