public UserSetting SaveUserSetting(UserSetting userSetting)
        {
            if (userSetting != null)
            {
                if (userSetting.UserSettingId == 0)  // this is new
                {
                    _ScrumTimeEntities.AddToUserSettings(userSetting);
                }
                else  // the userSetting exists
                {
                    _ScrumTimeEntities.AttachTo("UserSettings", userSetting);

                    ScrumTimeEntities freshScrumTimeEntities =
                        new ScrumTimeEntities(_ScrumTimeEntities.Connection.ConnectionString);
                    UserSetting existingUserSetting = GetUserSettingByUsername(freshScrumTimeEntities, userSetting.Username);
                    if (existingUserSetting == null)
                    {
                        throw new Exception("The user setting no longer exists.");
                    }
                    _ScrumTimeEntities.ObjectStateManager.ChangeObjectState(userSetting, System.Data.EntityState.Modified);
                }
                _ScrumTimeEntities.SaveChanges();
            }
            return userSetting;
        }
示例#2
0
        public static void CreateFirstTimeDefaults(string username)
        {
            ScrumTimeEntities scrumTimeEntities = new ScrumTimeEntities();
            UserSetting userSetting = UserSettingService.GetUserSettingByUsername(scrumTimeEntities, username);
            if (userSetting == null)
            {
                // Load sample product id
                ProductService productService = new ProductService(scrumTimeEntities);
                int productIdOfSample = productService.GetProductIdOfSample();
                if (productIdOfSample > -1)
                {
                    SprintService sprintService = new SprintService(scrumTimeEntities);
                    List<Sprint> mostRecentSprints = sprintService.GetMostRecentSprints(productIdOfSample, -1, 1);
                    if (mostRecentSprints.Count > 0 && mostRecentSprints[0] != null)
                    {
                        userSetting = new UserSetting()
                        {
                            CurrentProduct = productIdOfSample,
                            CurrentSprint = mostRecentSprints[0].SprintId,
                            LastMainTabSelected = 1,
                            Username = username
                        };
                        scrumTimeEntities.AddToUserSettings(userSetting);
                        scrumTimeEntities.SaveChanges(System.Data.Objects.SaveOptions.AcceptAllChangesAfterSave);
                    }

                }
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the UserSettings EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUserSettings(UserSetting userSetting)
 {
     base.AddObject("UserSettings", userSetting);
 }
 /// <summary>
 /// Create a new UserSetting object.
 /// </summary>
 /// <param name="userSettingId">Initial value of the UserSettingId property.</param>
 /// <param name="username">Initial value of the Username property.</param>
 public static UserSetting CreateUserSetting(global::System.Int32 userSettingId, global::System.String username)
 {
     UserSetting userSetting = new UserSetting();
     userSetting.UserSettingId = userSettingId;
     userSetting.Username = username;
     return userSetting;
 }