public int ChangeUserServiceArea(int areaId) { string areaName = ""; if (User.Identity.IsAuthenticated) { UserModel userModel = new UserModel(); UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name); UserDefaultArea defaultArea; if (userInfo.UserDefaultArea.Count == 0) { defaultArea = new UserDefaultArea(); defaultArea.UserId = userInfo.Id; defaultArea.AreaId = areaId; userModel.Add(defaultArea); } else { defaultArea = userModel.GetUserDefaultArea(userInfo.Id); defaultArea.AreaId = areaId; userModel.Save(); } areaName = defaultArea.ServiceArea.Value; } else { BaseDataModel baseModel = new BaseDataModel(); areaName = baseModel.GetServiceArea(areaId).Value; } System.Web.HttpCookie areaCookie = new System.Web.HttpCookie("udefaultarea"); areaCookie.Domain = BaseDataModel.CookieDomain; areaCookie.Values["Id"] = areaId.ToString(); areaCookie.Values["Name"] = HttpUtility.UrlEncode(areaName); areaCookie.Expires = DateTime.Now.AddYears(1); Response.Cookies.Set(areaCookie); return 1; }
/// <summary> /// 创建新的 UserDefaultArea 对象。 /// </summary> /// <param name="id">Id 属性的初始值。</param> /// <param name="userId">UserId 属性的初始值。</param> /// <param name="areaId">AreaId 属性的初始值。</param> public static UserDefaultArea CreateUserDefaultArea(global::System.Int32 id, global::System.Int32 userId, global::System.Int32 areaId) { UserDefaultArea userDefaultArea = new UserDefaultArea(); userDefaultArea.Id = id; userDefaultArea.UserId = userId; userDefaultArea.AreaId = areaId; return userDefaultArea; }
/// <summary> /// 用于向 UserDefaultArea EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToUserDefaultArea(UserDefaultArea userDefaultArea) { base.AddObject("UserDefaultArea", userDefaultArea); }
public void Add(UserDefaultArea area) { db.UserDefaultArea.AddObject(area); Save(); }