public JsonResult addUsersTag(string id) { IEnumerable<string> headerValues = Request.Headers.GetValues("Authorization"); String guid = headerValues.FirstOrDefault(); guid = guid.Replace("/", ""); CPSession retVal = TokenManager.getSessionInfo(guid); string userName = retVal.getAttributeValue("userName"); var _db = new ZestorkContainer(); var userSkillTag = new UserSkills { Username = userName, Skill = id, Rating = "0" }; _db.UserSkills.Add(userSkillTag); try { _db.SaveChanges(); } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); return Json(500, JsonRequestBehavior.AllowGet); } return Json(200, JsonRequestBehavior.AllowGet); }
public LogOnModel Login(string userName, string passwrod, string returnUrl, string keepMeSignedIn) { var _db = new ZestorkContainer(); var userData = new LogOnModel(); if (_db.Users.Any(x => x.Username == userName && x.Password == passwrod)) { Users user = _db.Users.SingleOrDefault(x => x.Username == userName && x.isActive=="true"); if (user != null) { userData.User = new User(); //user is already registered userData.User.FirstName = user.FirstName; userData.User.LastName = user.LastName; userData.User.Username = user.Username; userData.User.Gender = user.gender; userData.User.ImageUrl = user.ImageUrl; userData.User.Email = user.Username; try { if (keepMeSignedIn == "true") user.KeepMeSignedIn = "true"; else user.KeepMeSignedIn = "false"; _db.SaveChanges(); } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); } userData.User.keepMeSignedIn = user.KeepMeSignedIn; userData.statusCode = "200"; } else userData.statusCode = "403"; } else userData.statusCode = "401"; userData.ReturnUrl = returnUrl; return userData; }
public JsonResult changeUserPassword(changePasswordRequest req) { IEnumerable<string> headerValues = Request.Headers.GetValues("Authorization"); String guid = headerValues.FirstOrDefault(); guid = guid.Replace("/", ""); CPSession retVal = TokenManager.getSessionInfo(guid); string userName = retVal.getAttributeValue("userName"); var _db = new ZestorkContainer(); Users User = _db.Users.SingleOrDefault(x => x.Username == userName); User.Password = req.password; try { _db.SaveChanges(); } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); return Json(500); } return Json(200); }
public JsonResult submitUserPageTopbar(string id) { IEnumerable<string> headerValues = Request.Headers.GetValues("Authorization"); String guid = headerValues.FirstOrDefault(); guid = guid.Replace("/", ""); CPSession retVal = TokenManager.getSessionInfo(guid); string userName = retVal.getAttributeValue("userName"); var _db = new ZestorkContainer(); var UserPageTheme = _db.UserPageSettings.SingleOrDefault(x => x.Username == userName); if (UserPageTheme == null) { UserPageTheme = new UserPageSetting { Username = userName, TopBar = id }; _db.UserPageSettings.Add(UserPageTheme); } else { UserPageTheme.TopBar = id; } try { _db.SaveChanges(); } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); return Json(500, JsonRequestBehavior.AllowGet); } return Json(200, JsonRequestBehavior.AllowGet); }
public LogOnModel Login(string returnUrl, string AbsoluteUri, string oauth_token, string oauth_verifier, string referral,string userType) { var userData = new LogOnModel(); var _db = new ZestorkContainer(); string authLink = string.Empty; if (oauth_token != null && oauth_verifier != null) { var linkedInApiDataResponse = _db.LinkedInAuthApiDatas.SingleOrDefault(x => x.oauth_Token == oauth_token); if (linkedInApiDataResponse != null) { GetAccessToken(oauth_token, linkedInApiDataResponse.oauth_TokenSecret, oauth_verifier); String UserDetailString = RequestProfile(_oauth.Token, _oauth.TokenSecret, oauth_verifier); var UserDetails = JsonConvert.DeserializeObject<linkedinUserDataWrapper>(Convert.ToString(UserDetailString)); _db.LinkedInAuthApiDatas.Attach(linkedInApiDataResponse); _db.LinkedInAuthApiDatas.Remove(linkedInApiDataResponse); //_db.SaveChanges(); userData.User = new User(); if (_db.Users.Any(x => x.Username == UserDetails.emailAddress)) { Users user = _db.Users.SingleOrDefault(x => x.Username == UserDetails.emailAddress); //user is already registered userData.User.FirstName = user.FirstName; userData.User.LastName = user.LastName; userData.User.Username = user.Username; userData.User.Gender = user.gender; userData.User.ImageUrl = user.ImageUrl; userData.statusCode = "200"; } else { // add user in database String ID = Guid.NewGuid().ToString(); userData.User.FirstName = UserDetails.firstName; userData.User.LastName = UserDetails.lastName; userData.User.Username = UserDetails.emailAddress; try { userData.User.Email = UserDetails.emailAddress; } catch (Exception) { userData.User.Email = "NA"; } userData.User.Gender = "NA"; userData.User.ImageUrl = "NA"; userData.User.Username = UserDetails.emailAddress; var user = new Users { Username = UserDetails.emailAddress, Password = Guid.NewGuid().ToString(), Source = "linkedin", isActive = "true", Type = userType != null ? userType : "NA", guid = Guid.NewGuid().ToString(), FirstName = UserDetails.firstName, LastName = UserDetails.lastName, gender = "NA", ImageUrl = "NA" }; _db.Users.Add(user); try { _db.SaveChanges(); userData.statusCode = "200"; } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); throw; } } } } else { authLink = CreateAuthorization(); var linkedInApiData = new LinkedInAuthApiData { oauth_Token = _oauth.Token, oauth_TokenSecret = _oauth.TokenSecret, oauth_verifier = "" }; _db.LinkedInAuthApiDatas.Add(linkedInApiData); try { _db.SaveChanges(); } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); throw; } userData.ReturnUrl = authLink; } return userData; }
public JsonResult forgetPassword(string id) { var _db = new ZestorkContainer(); String guid = Guid.NewGuid().ToString(); String guidSession = Request.QueryString["guidSession"].ToString(); if (_db.Users.Any(x => x.Username == id)) { AccountController AccountController = new AccountController(); Users UserDetail = _db.Users.SingleOrDefault(x => x.Username == id); if (UserDetail.Source == "facebook") { UserDetail.Locked = "false"; UserDetail.Password = guid; try { _db.SaveChanges(); try { TokenManager.removeSession(guidSession); } catch (Exception) { //no need to remove the session if it is invalid... } return Json(210, JsonRequestBehavior.AllowGet); // unreachable code //210 for facebook.. } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); return Json(500, JsonRequestBehavior.AllowGet); // unreachable code } } else { if (UserDetail != null) { var forgetPasswordDataAlreadyExists = _db.ForgetPasswords.SingleOrDefault(x => x.Username == id); if (forgetPasswordDataAlreadyExists != null) _db.ForgetPasswords.Remove(forgetPasswordDataAlreadyExists); var forgetPasswordData = new ForgetPassword { Username = id, guid = guid }; _db.ForgetPasswords.Add(forgetPasswordData); try { _db.SaveChanges(); forgetPasswordValidationEmail forgetPasswordValidationEmail = new forgetPasswordValidationEmail(); forgetPasswordValidationEmail.sendForgetPasswordValidationEmailMessage(id, guid, Request); } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); return Json(500, JsonRequestBehavior.AllowGet); } } else { return Json(404, JsonRequestBehavior.AllowGet); } return Json(200, JsonRequestBehavior.AllowGet); } } else { return Json("Username doesn't exists..", JsonRequestBehavior.AllowGet); } }
// // GET: /Locked/ public ActionResult Index(string id) { var _db = new ZestorkContainer(); CPSession retVal = TokenManager.getSessionInfo(id); string userName = retVal.getAttributeValue("userName"); Users User = _db.Users.SingleOrDefault(x => x.Username == userName); LockedScreenModel userInfo = new LockedScreenModel(); userInfo.firstName = User.FirstName; userInfo.lastName = User.LastName; if (User.ImageUrl == "NA" || User.ImageUrl == null) userInfo.imageUrl = "../../Resource/templates/afterLogin/web/img/demo/user-avatar.jpg"; else userInfo.imageUrl = User.ImageUrl; if (userInfo.imageUrl.Contains("../../")) { userInfo.imageUrl = "../" + userInfo.imageUrl; } userInfo.message = ""; userInfo.guid = id; userInfo.userName = User.Username; userInfo.postUrl = "http://" + Request.Url.Authority + "Locked/unlock/" + id; User.Locked = "true"; UserPageSetting pageSetting = _db.UserPageSettings.SingleOrDefault(x => x.Username == userName); if (pageSetting != null) userInfo.PageThemeColor = "theme-" + pageSetting.PageThemeColor; else userInfo.PageThemeColor = ""; try { _db.SaveChanges(); } catch (DbEntityValidationException e) { dbContextException dbContextException = new dbContextException(); dbContextException.logDbContextException(e); throw; } return View(userInfo); }
public JsonResult UploadToAlbum(String id) { var _db = new ZestorkContainer(); CPSession retVal = TokenManager.getSessionInfo(id); string userName = retVal.getAttributeValue("userName"); var user = _db.Users.SingleOrDefault(x => x.Username == userName); if (user != null) { HttpPostedFileBase photo = Request.Files["photo"]; imageService imageService = new Service.imageService(); string uploadedImageLink = imageService.imgurUploadImage(photo); //string[] imageUrlSplitted = uploadedImageLink.Split('.'); ////http://i.imgur.com/uFxYj82.jpg //string ImgurId = imageUrlSplitted[2]; //string uploadedImageLinkMedium = imageUrlSplitted[0] + "." + imageUrlSplitted[1] + "." + imageUrlSplitted[2] + "m." + imageUrlSplitted[3]; //saving medium size image url in db.. user.ImageUrl = uploadedImageLink; try { _db.SaveChanges(); if (user.Type == "client") Response.Redirect("/Client#/edit"); else Response.Redirect("/secure#/edit"); return Json(200, JsonRequestBehavior.AllowGet); } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); return Json("Internal Server Error Occured !!", JsonRequestBehavior.AllowGet); } } else return Json("invalid username !!!"); }
public ActionResult unlock() { var _db = new ZestorkContainer(); string userName = Request.Form["username"].ToString(); String password = Request.Form["password"].ToString(); String id = Request.Form["id"].ToString(); if (_db.Users.Any(x => x.Username == userName && x.Password == password)) { Users user = _db.Users.SingleOrDefault(x => x.Username == userName && x.isActive == "true"); if (user != null) { user.Locked = "false"; try { _db.SaveChanges(); try { CPSession retVal = TokenManager.getSessionInfo(id); TokenManager.removeSession(id);// remove session if available. } catch (Exception) { //if session is not available.. leave it. } #region Session CPSession session = new CPSession(); session.addAttribute("userName", userName); bool isPersistent = false; // as of now we have only 1 type of login TokenManager.CreateSession(session, isPersistent); #endregion Response.Redirect("/Account/welcome?guid=" + session.getID() + "&username="******"/#/"); } catch (DbEntityValidationException e) { dbContextException dbContextException = new dbContextException(); dbContextException.logDbContextException(e); throw; } } Users User = _db.Users.SingleOrDefault(x => x.Username == userName); LockedScreenModel userInfo = new LockedScreenModel(); userInfo.firstName = User.FirstName; userInfo.lastName = User.LastName; if (User.ImageUrl == "NA" || User.ImageUrl == null) userInfo.imageUrl = "../../Resource/templates/afterLogin/web/img/demo/user-avatar.jpg"; else userInfo.imageUrl = User.ImageUrl; if (userInfo.imageUrl.Contains("../../")) { userInfo.imageUrl = "../" + userInfo.imageUrl; } userInfo.message = "Enter Your Password to Unlock !!"; userInfo.guid = id; userInfo.userName = User.Username; userInfo.postUrl = "http://" + Request.Url.Authority + "Locked/unlock/" + id; User.Locked = "true"; UserPageSetting pageSetting = _db.UserPageSettings.SingleOrDefault(x => x.Username == userName); if (pageSetting != null) userInfo.PageThemeColor = "theme-" + pageSetting.PageThemeColor; else userInfo.PageThemeColor = ""; userInfo.message = "Inactive Account."; return View("index", userInfo); } else { Users User = _db.Users.SingleOrDefault(x => x.Username == userName); LockedScreenModel userInfo = new LockedScreenModel(); userInfo.firstName = User.FirstName; userInfo.lastName = User.LastName; if (User.ImageUrl == "NA" || User.ImageUrl == null) userInfo.imageUrl = "../../Resource/templates/afterLogin/web/img/demo/user-avatar.jpg"; else userInfo.imageUrl = User.ImageUrl; if (userInfo.imageUrl.Contains("../../")) { userInfo.imageUrl = "../" + userInfo.imageUrl; } userInfo.guid = id; userInfo.userName = User.Username; userInfo.postUrl = "http://" + Request.Url.Authority + "Locked/unlock/" + id; User.Locked = "true"; UserPageSetting pageSetting = _db.UserPageSettings.SingleOrDefault(x => x.Username == userName); if (pageSetting != null) userInfo.PageThemeColor = "theme-" + pageSetting.PageThemeColor; else userInfo.PageThemeColor = ""; userInfo.message = "invalid entry !! try again."; return View("index", userInfo); } }
public ActionResult validateForgetPassword() { var _db = new ZestorkContainer(); String guid = Request.QueryString["guid"]; String username = Request.QueryString["username"]; if (!_db.Users.Any(x => x.Username == username)) { Response.Redirect("/"); } if(_db.ForgetPasswords.Any(x=>x.Username == username && x.guid == guid)) { var removeForgetPasswordData = _db.ForgetPasswords.SingleOrDefault(x => x.Username == username); _db.ForgetPasswords.Remove(removeForgetPasswordData); var UserData = _db.Users.SingleOrDefault(x => x.Username == username); UserData.Password = Guid.NewGuid().ToString(); UserData.Locked = "false"; try { _db.SaveChanges(); } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); } #region Session CPSession session = new CPSession(); session.addAttribute("userName", username); bool isPersistent = false; // as of now we have only 1 type of login TokenManager.CreateSession(session, isPersistent); #endregion Response.Redirect("/Account/welcome?guid=" + session.getID() + "&username="******"/#/"); } else { Response.Redirect("/#/forgetpassword"); } return View("Home","Index"); }
public ActionResult CreateAccount(CreateAccountRequest req) { logger.Info("new account creation request"); var _db = new ZestorkContainer(); String emailRetVal = String.Empty; //if user already exists if(_db.Users.Any(x=>x.Username==req.userName)) return Json(new { code="402",msg="User Already Exists" }); String ID = Guid.NewGuid().ToString(); var user = new Users { Username = req.userName, Password = req.password, Source = req.source, isActive = "false", Type = req.type, guid = Guid.NewGuid().ToString(), FirstName = req.firstName, LastName = req.lastName, gender = "NA", ImageUrl = "NA" }; _db.Users.Add(user); if (req.referral != null && req.referral != "") { var referral = new RecommendedBy { RecommendedFrom = req.referral, RecommendedTo = req.userName }; _db.RecommendedBies.Add(referral); } if (req.type == "client") { var clientDetails = new ClientDetails { Username = req.userName, CompanyName = req.CompanyName }; _db.ClientDetails.Add(clientDetails); } var ValidateUserKey = new ValidateUserKey { Username = req.userName, guid = ID }; _db.ValidateUserKeys.Add(ValidateUserKey); try { _db.SaveChanges(); sendAccountCreationValidationEmail sendAccountCreationValidationEmail = new sendAccountCreationValidationEmail(); emailRetVal = sendAccountCreationValidationEmail.sendAccountCreationValidationEmailMessage(req.userName, ID,Request); } catch (DbEntityValidationException e) { dbContextException.logDbContextException(e); throw; } //Users User = _db.Users.SingleOrDefault(x => x.Username == req.userName); //ValidateUserKey key = _db.ValidateUserKeys.SingleOrDefault(x => x.Username == req.userName); return Json(new { code="200",msg="successfully created account" }); }
public JsonResult validateAccount(ValidateAccountRequest req) { var _db = new ZestorkContainer(); if (_db.ValidateUserKeys.Any(x => x.Username == req.userName && x.guid == req.guid)) { Users User = _db.Users.SingleOrDefault(x => x.Username == req.userName); User.isActive = "true"; try { _db.SaveChanges(); } catch (DbEntityValidationException e) { dbContextException.logDbContextException(e); throw; } return Json(new { code = "200", msg = "account validated successfully" }); } else { return Json(new { code = "402", msg = "Link might be expired" }); } }
public JsonResult logout(string id) { try { var _db = new ZestorkContainer(); CPSession retVal = TokenManager.getSessionInfo(id); if (retVal != null) { string userName = retVal.getAttributeValue("userName"); Users user = _db.Users.SingleOrDefault(x => x.Username == userName); if (user != null) { try { user.KeepMeSignedIn = "false"; _db.SaveChanges(); } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); } } TokenManager.removeSession(id); } else { string username = Request.QueryString["username"].ToString(); if (username != null || username != "") { username = username.Split('/')[0]; Users user = _db.Users.SingleOrDefault(x => x.Username == username); if (user != null && user.KeepMeSignedIn != null) { if (user.KeepMeSignedIn == "true") { try { user.KeepMeSignedIn = "false"; _db.SaveChanges(); } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); } } } } } Response.Redirect("/"); return Json(200, JsonRequestBehavior.AllowGet); // unreachable code } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); Response.Redirect("/"); return Json(500, JsonRequestBehavior.AllowGet); // unreachable code } }
public JsonResult forgetPassword(string id) { var _db = new ZestorkContainer(); String guid = Guid.NewGuid().ToString(); if (_db.Users.Any(x => x.Username == id)) { var forgetPasswordDataAlreadyExists = _db.ForgetPasswords.SingleOrDefault(x => x.Username == id); if (forgetPasswordDataAlreadyExists != null) _db.ForgetPasswords.Remove(forgetPasswordDataAlreadyExists); var forgetPasswordData = new ForgetPassword { Username = id, guid = guid }; _db.ForgetPasswords.Add(forgetPasswordData); try { _db.SaveChanges(); forgetPasswordValidationEmail forgetPasswordValidationEmail = new forgetPasswordValidationEmail(); forgetPasswordValidationEmail.sendForgetPasswordValidationEmailMessage(id, guid, Request); } catch (DbEntityValidationException e) { dbContextException.logDbContextException(e); return Json(500, JsonRequestBehavior.AllowGet); } } else { return Json(404, JsonRequestBehavior.AllowGet); } return Json(200, JsonRequestBehavior.AllowGet); }
public LogOnModel Login(string returnUrl, string code, string referral,string userType) { var _db = new ZestorkContainer(); var userData = new LogOnModel(); string app_id = ""; string app_secret = ""; app_id = ConfigurationManager.AppSettings["googleAppID"].ToString(); app_secret = ConfigurationManager.AppSettings["googleAppSecret"].ToString(); //if (returnUrl.Contains("zestork.pcongo")) //{ // app_id = ConfigurationManager.AppSettings["googleAppIDZestork"].ToString(); // app_secret = ConfigurationManager.AppSettings["googleAppSecretZestork"].ToString(); //} //else //{ // app_id = ConfigurationManager.AppSettings["googleAppID"].ToString(); // app_secret = ConfigurationManager.AppSettings["googleAppSecret"].ToString(); //} string scope = "email%20profile"; if (code == null) { userData.ReturnUrl = (string.Format( "https://accounts.google.com/o/oauth2/auth?scope={0}&state=%2Fprofile&redirect_uri={1}&response_type=code&client_id={2}&approval_prompt=force", scope, returnUrl, app_id)); logger.Info(userData.ReturnUrl); return userData; } else { string access_token = getGoogleAuthToken(returnUrl, scope, code, app_id, app_secret); String URI = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + access_token; logger.Info(URI); WebClient webClient = new WebClient(); Stream stream = webClient.OpenRead(URI); string googleUserDetailString; /*I have not used any JSON parser because I do not want to use any extra dll/3rd party dll*/ using (StreamReader br = new StreamReader(stream)) { googleUserDetailString = br.ReadToEnd(); } var googleUserDetails = JsonConvert.DeserializeObject<googleUserDetails>(Convert.ToString(googleUserDetailString)); userData.User = new User(); if (_db.Users.Any(x => x.Username == googleUserDetails.email)) { Users user = _db.Users.SingleOrDefault(x => x.Username == googleUserDetails.email); //user is already registered userData.User.FirstName = user.FirstName; userData.User.LastName = user.LastName; userData.User.Username = user.Username; userData.User.Gender = user.gender; userData.User.ImageUrl = user.ImageUrl; userData.statusCode = "200"; } else { // add user in database String ID = Guid.NewGuid().ToString(); userData.User.FirstName = googleUserDetails.given_name; userData.User.LastName = googleUserDetails.family_name; try { userData.User.Username = googleUserDetails.email; userData.User.Email = googleUserDetails.email; } catch (Exception) { userData.User.Username = "******"; userData.User.Email = "NA"; } try { userData.User.Gender = googleUserDetails.gender; } catch (Exception) { userData.User.Gender = "NA"; throw; } try { userData.User.ImageUrl = googleUserDetails.picture; } catch (Exception) { userData.User.ImageUrl = "NA"; } if (userData.User.Gender == null) userData.User.Gender = "NA"; logger.Info(JsonConvert.SerializeObject(userData)); var user = new Users { Username = userData.User.Email, Password = Guid.NewGuid().ToString(), Source = "google", isActive = "true", Type = userType != null ? userType : "NA", guid = Guid.NewGuid().ToString(), FirstName = userData.User.FirstName, LastName = userData.User.LastName, gender = userData.User.Gender, ImageUrl = userData.User.ImageUrl, }; _db.Users.Add(user); try { _db.SaveChanges(); userData.statusCode = "200"; } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); throw; } } } return userData; }
private LogOnModel checkFacebookAuthorization(string returnUrl, string code, string userType) { var userData = new LogOnModel(); try { var _db = new ZestorkContainer(); string app_id = string.Empty; string app_secret = string.Empty; app_id = ConfigurationManager.AppSettings["FacebookAppID"].ToString(); app_secret = ConfigurationManager.AppSettings["FacebookAppSecret"].ToString(); string scope = ""; if (code == null) { userData.ReturnUrl = (string.Format( "https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}", app_id, returnUrl, scope)); return userData; } else { string access_token = getFacebookAuthToken(returnUrl, scope, code,app_id,app_secret); var client = new FacebookClient(access_token); dynamic me = client.Get("me"); String userName = Convert.ToString(me.username); userData.User = new User(); if (_db.Users.Any(x => x.Username == userName + "@facebook.com")) { Users user = _db.Users.SingleOrDefault(x => x.Username == userName + "@facebook.com"); //user is already registered userData.User.FirstName = user.FirstName; userData.User.LastName = user.LastName; userData.User.Username = user.Username; userData.User.Gender = user.gender; userData.User.ImageUrl = user.ImageUrl; userData.statusCode = "200"; } else { // add user in database String ID = Guid.NewGuid().ToString(); String ImageUrl = FacebookService.GetPictureUrl(userName); userData.User.FirstName = me.first_name; userData.User.LastName = me.last_name; userData.User.Username = me.username; userData.User.ImageUrl = ImageUrl; userData.User.Username = userName + "@facebook.com"; var user = new Users { Username = userName + "@facebook.com", Password = Guid.NewGuid().ToString(), Source = "facebook", isActive = "true", Type = userType!=null?userType:"NA", guid = Guid.NewGuid().ToString(), FirstName = me.first_name, LastName = me.last_name, gender = "NA", ImageUrl = ImageUrl }; _db.Users.Add(user); try { _db.SaveChanges(); userData.statusCode = "200"; } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); throw; } } } } catch (Exception ex) { logger.Error("facebook login error", ex); throw; } return userData; }