/// <summary> /// Adds the specified address. /// </summary> /// <param name="address">The address.</param> /// <returns></returns> public Guid Add(tbl_Address address) { address.ID = Guid.NewGuid(); _dataContext.tbl_Address.AddObject(address); _dataContext.SaveChanges(); return(address.ID); }
/// <summary> /// Updates the specified address. /// </summary> /// <param name="address">The address.</param> public void Update(tbl_Address address) { var toUpdate = _dataContext.tbl_Address.Where(a => a.ID == address.ID).SingleOrDefault(); if (toUpdate != null) { toUpdate.CountryID = address.CountryID; toUpdate.RegionID = address.RegionID; toUpdate.DistrictID = address.DistrictID; toUpdate.CityID = address.CityID; toUpdate.Address = address.Address; _dataContext.SaveChanges(); } }
/// <summary> /// Ths function adds the address /// </summary> /// <param name="address"></param> public bool AddAddress(Address address) { var context = new dbDataContext(); tbl_Address newAddress = null; if (address.AddressId > 0) { //check the address with address id newAddress = context.tbl_Addresses.FirstOrDefault(t => t.AddressId == address.AddressId); } else if (address.Type.ToLower().Equals("general")) { // if type is general then just update record newAddress = context.tbl_Addresses.FirstOrDefault( t => t.RefId == address.RefId && t.RefType.Equals(address.RefType) && t.Type.ToLower().Equals("general")); } if (newAddress == null) newAddress = new tbl_Address(); //fill the values newAddress.Address1 = address.Address1; newAddress.Address2 = address.Address2; newAddress.Address3 = address.Address3; newAddress.City = address.City; newAddress.Country = address.Country; newAddress.County = address.County; newAddress.Postcode = address.Postcode; newAddress.RefId = address.RefId; newAddress.RefType = address.RefType; newAddress.Type = address.Type; // add if a new record if (newAddress.AddressId < 1) { context.tbl_Addresses.InsertOnSubmit(newAddress); } context.SubmitChanges(); return true; }
/// <summary> /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface. /// </summary> /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param> public void ProcessRequest(HttpContext context) { var dataManager = new DataManager(); if (!string.IsNullOrEmpty(context.Request.QueryString["code"]) && !string.IsNullOrEmpty(context.Request.QueryString["psid"])) { var portalSettingsId = Guid.Parse(context.Request.QueryString["psid"].Substring(0, 36)); var domain = context.Request.QueryString["psid"].Substring(36, context.Request.QueryString["psid"].Length - 36); var api = new VkontakteAPI(context.Request.QueryString["code"]); var userProfile = api.GetProfile(); var country = api.GetCountry(userProfile.country); var city = api.GetCity(userProfile.city); var portalSettings = dataManager.PortalSettings.SelectById(portalSettingsId); var siteId = portalSettings.SiteID; var user = dataManager.User.SelectByEmail(siteId, userProfile.screen_name); if (user == null) { var contactId = dataManager.User.RegisterUser(siteId, string.Format("{0} {1}", userProfile.first_name, userProfile.last_name), userProfile.screen_name, string.Empty, Guid.NewGuid().ToString()); var contact = dataManager.Contact.SelectById(siteId, contactId); var tblCountry = dataManager.Country.SelectByTitle(country.name); var tblCity = dataManager.City.SelectByTitle(city.name); if (tblCountry != null || tblCity != null) { var address = new tbl_Address(); if (tblCountry != null) { address.CountryID = tblCountry.ID; } if (tblCity != null) { address.CityID = tblCity.ID; } contact.AddressID = dataManager.Address.Add(address); } DateTime birthDate; if (DateTime.TryParse(userProfile.bdate, out birthDate)) { contact.BirthDate = birthDate; } dataManager.Contact.Update(contact); user = dataManager.User.SelectByContactId(siteId, contact.ID); var contactCommunication = new tbl_ContactCommunication { ContactID = contact.ID, CommunicationNumber = userProfile.uid, CommunicationType = (int)CommunicationType.VKontakte }; dataManager.ContactCommunication.Add(contactCommunication); } var socialAuthToken = new tbl_SocialAuthorizationToken { UserID = user.ID, PortalSettingsID = portalSettingsId, ExpirationDate = DateTime.Now.AddMinutes(5) }; socialAuthToken = dataManager.SocialAuthorizationToken.Add(socialAuthToken); var url = HttpUtility.UrlDecode(context.Request.Url.ToString()) .Replace(HttpUtility.UrlDecode(context.Request.Url.Query), "") .Replace(HttpUtility.UrlDecode(context.Request.Url.Host), HttpUtility.UrlDecode(domain)); context.Response.Redirect(url + "?sat=" + socialAuthToken.ID, true); } else if (!string.IsNullOrEmpty(context.Request.QueryString["sat"])) { var socialAuthToken = dataManager.SocialAuthorizationToken.SelectById(Guid.Parse(context.Request.QueryString["sat"])); if (socialAuthToken != null && socialAuthToken.ExpirationDate > DateTime.Now) { dataManager.SocialAuthorizationToken.Delete(socialAuthToken.ID); FormsAuthentication.SetAuthCookie(socialAuthToken.UserID.ToString(), true); } context.Response.Write("<script type=\"text/javascript\">window.opener.document.location.href = window.opener.document.location.href;window.close();</script>"); } else { context.Response.Write("<script type=\"text/javascript\">window.opener.document.location.href = window.opener.document.location.href;window.close();</script>"); } }
partial void Deletetbl_Address(tbl_Address instance);
partial void Updatetbl_Address(tbl_Address instance);
partial void Inserttbl_Address(tbl_Address instance);