public void Post(ref UserModel model) { //validate userid exists in system User user = uctx.GetById("Users", SimpleHash.GenerateHashKey(model.UserName)); bool isFaceBookuser = IsFacebookUser(model); //bool doesUserExists = (user != null && DoesFbUserExists(model, user)); if (user!=null) throw new Exception(); //user id already exists . else { if (isFaceBookuser) model.Password = model.FacebookId; user = UserModel.FromModel(model); user.AgeCheck= model.AppState == AppStateType.AgeCheckComplete ? user.AgeCheck = true:user.AgeCheck=false; user.TCCheck = model.AppState == AppStateType.TCComplete ? user.TCCheck = true : user.TCCheck = false; user.IsOnline = true; user.IsActive = true; uctx.AddObject(user); } if (user.Latitude != 0 && user.Longitude != 0) UpdateUserLocation(user.Latitude, user.Longitude, user.UserId); if (!string.IsNullOrEmpty(user.ChatId)) UpdateUserChat(user.ChatId, user.UserId); if (!string.IsNullOrEmpty(user.DeviceId)) UpdateUserDevices(user); model = UserModel.FromEntity(user); }
public void Post(ref UserModel model) { //validate userid exists in system User user = uctx.GetById("Users", SimpleHash.GenerateHashKey(model.UserName)); bool fbuserexists = DoesFacebookUserExists(model, user); if (user != null && !fbuserexists) { throw new Exception(); //user id already exists . } if (!fbuserexists) { user = UserModel.FromModel(model); user.IsOnline = true; user.IsActive = true; uctx.AddObject(user); } if (user.Latitude != 0 && user.Longitude != 0) UpdateUserLocation(user.Latitude, user.Longitude, user.UserId); if (!string.IsNullOrEmpty(user.ChatId)) UpdateUserChat(user.ChatId, user.UserId); if (!string.IsNullOrEmpty(user.DeviceId)) UpdateUserDevices(user); model = UserModel.FromEntity(user); }
public ActionResult Create(UserModel usermodel) { if (ModelState.IsValid) { rep.Post(ref usermodel); return RedirectToAction("Index"); } return View(usermodel); }
public ActionResult Edit(UserModel usermodel) { if (ModelState.IsValid) { rep.Update(usermodel); return RedirectToAction("Index"); } return View(usermodel); }
internal static User FromModel(UserModel model, User user) { if (!String.IsNullOrEmpty(model.UserName)) user.UserName = model.UserName; if (!String.IsNullOrEmpty(model.Password)) user.Password = model.Password; user.IsActive = model.IsActive; user.IsAdmin = model.IsAdmin; if (!String.IsNullOrEmpty(model.Gender)) user.Gender = model.Gender; user.Latitude = model.Latitude; user.Longitude = model.Longitude; if (!String.IsNullOrEmpty(model.ChatId)) user.ChatId = model.ChatId; if (!String.IsNullOrEmpty(model.DeviceId)) user.DeviceId = model.DeviceId; if (!String.IsNullOrEmpty(model.DeviceName)) user.DeviceName = model.DeviceName; if (!String.IsNullOrEmpty(model.DeviceVersion)) user.DeviceVersion = model.DeviceVersion; if (!String.IsNullOrEmpty(model.DevicePlatform)) user.DevicePlatform = model.DevicePlatform; if (!String.IsNullOrEmpty(model.DevicePhGapVersion)) user.DevicePhGapVersion = model.DevicePhGapVersion; if (!string.IsNullOrEmpty(model.FacebookId)) user.FacebookId = model.FacebookId; user.IsOnline = model.IsOnline; if (model.AppState != AppStateType.NoState) user.AppState = model.AppState; user.AgeCheck = (model.AppState == AppStateType.AgeCheckComplete) ? user.AgeCheck = true : user.AgeCheck = false; user.TCCheck = (model.AppState == AppStateType.TCComplete) ? user.TCCheck = true : user.TCCheck = false; return user; }
internal static User FromModel(UserModel model) { return new User { UserPartition = "Users", UserId = model.UserName, UserName = model.UserName, Password = model.Password, IsAdmin = model.IsAdmin, Gender = model.Gender, IsActive = model.IsActive, Longitude = model.Longitude, Latitude = model.Latitude, ChatId = model.ChatId , DeviceId = model.DeviceId , DeviceName = model.DeviceName , DeviceVersion = model.DeviceVersion , DevicePlatform = model.DevicePlatform , DevicePhGapVersion = model.DevicePhGapVersion , IsOnline = model.IsOnline , FacebookId = model.FacebookId , AppState = model.AppState, FirstName = model.FirstName , LastName = model.LastName , Locale= model.Locale}; }
public UserModel ChangePassword(UserModel model, string newPassword) { model.Password = newPassword; this.Update(model); return model; }
private bool IsLocationChanged(UserModel model, User user) { return (model.Longitude != user.Longitude || model.Latitude != user.Latitude); }
private bool IsDeviceIdChanged(UserModel model, User user) { return (model.DeviceId != user.DeviceId); }
private bool IsChatIdChanged(UserModel model, User user) { return (model.ChatId != user.ChatId); }
private static bool DoesFacebookUserExists(UserModel model, User user) { if (user!=null && !string.IsNullOrEmpty(user.FacebookId) && user.FacebookId == model.FacebookId) { return true; } return false; }
public void Update(UserModel model) { User user = uctx.GetById("Users", model.UserId); if (user == null) throw new Exception(); //TODO: does not exists bool islocChanged = IsLocationChanged(model, user); bool isChatChanged = IsChatIdChanged(model, user); bool isDeviceChanged = IsDeviceIdChanged(model, user); user = UserModel.FromModel(model, user); if (islocChanged) UpdateUserLocation(user.Latitude, user.Longitude, user.UserId); if (isChatChanged) UpdateUserChat(user.ChatId, user.UserId); if (isDeviceChanged) UpdateUserDevices(user); user.IsOnline = true; uctx.UpdateObject(user, false); }
//private static bool DoesFbUserExists(UserModel model, User user) //{ // if (user!=null && !string.IsNullOrEmpty(user.FacebookId) && user.FacebookId == model.FacebookId) // { // return true; // } // return false; //} private static bool IsFacebookUser(UserModel model) { if (model != null && !string.IsNullOrEmpty(model.FacebookId)) { return true; } return false; }