Beispiel #1
0
        //Get Profile Data such as First Name , Last Name, Date Of Birth and Language by this get method of Profile controller.
        public HttpResponseMessage ProfileDetails()
        {
            // Fetch User ID from Basic Authentication
            string ID = Thread.CurrentPrincipal.Identity.Name;

            //Check Whether model is valid or not.
            //IF yes then pass the data from entity model(database) to Model class.
            if (ModelState.IsValid)
            {
                // Create getProfileModel object of GetProfileModel class
                ProfileModel getProfileModel = new ProfileModel();

                //Query statement for specific ID.
                var context = new WebApiEntities();
                var query   = from user in context.ProfileTables where ID == user.UserID.ToString() select user;

                // Profile is the Class of
                ProfileTable profile = query.FirstOrDefault();

                // get profile Values
                getProfileModel.Fname    = profile.FirstName;
                getProfileModel.Lname    = profile.LastName;
                getProfileModel.Language = profile.Language;
                getProfileModel.DOB      = profile.DOB.ToString();

                // Return getProfileModel class data with Ok status of HttpMessageResponse.
                return(Request.CreateResponse(HttpStatusCode.OK, getProfileModel));
            }

            //Create Error Response if Model State is not valid and Send Message to user Please login again.
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "please login again"));
        }
Beispiel #2
0
 public static ProfileTable GetProfileTable()
 {
     if (profileTable == null)
     {
         profileTable = new ProfileTable();
     }
     return(profileTable);
 }
Beispiel #3
0
 public InventoryController()
 {
     this._inventoryTable = new InventoryTable();
     this._userTable      = new UserTable();
     this._locationTable  = new LocationTable();
     this._profileTable   = new ProfileTable();
     this._hardwareTable  = new HardwareTable();
     this._logTable       = new LogBook.Controllers.LogBookController();
 }
 /// <summary>
 ///     Initializes the models
 /// </summary>
 /// <author>
 ///     Juan Bautista
 /// </author>
 public MovementController()
 {
     this._profileTable       = new ProfileTable("MovementProfiles");
     this._movementTable      = new MovementTable();
     this._processTable       = new ProcessesTable();
     this._processDiagram     = new ProcessDiagram();
     this._authorizationTable = new AuthorizationTable();
     this._userTable          = new UserTable();
     this._demandTable        = new DemandTable();
 }
 public MovementProfileController()
 {
     this._profileTable       = new ProfileTable("MovementProfiles");
     this._movementTable      = new MovementTable();
     this._userTeble          = new UserTable();
     this._authorizationTable = new AuthorizationTable();
     this._categoryTable      = new CategoryTable();
     validatepermissions      = new validatePermissions();
     this._processesTable     = new ProcessesTable();
     _logTable = new LogBook.Controllers.LogBookController();
 }
    protected void button1_Click(object sender, EventArgs e)
    {
        ProfileTable pf = new ProfileTable();

        pf.Name      = TextBox1.Text;
        pf.MobNo     = TextBox2.Text;
        pf.Email     = TextBox3.Text;
        pf.Password  = TextBox4.Text;
        pf.CPassword = TextBox5.Text;
        dl.da.ProfileTables.InsertOnSubmit(pf);
        dl.da.SubmitChanges();
        Response.Write("<script>alert('Thanks For SignUp!!')</script>");
    }
 public EmployeeController()
 {
     //  validatelim = new ValidateLimits();
     validatepermissions  = new validatePermissions();
     employeeprofileTable = new EmployeeProfileTable();
     witnessesModel       = new MongoModel("witnesses");
     _listTable           = new ListTable();
     employeetable        = new EmployeeTable();
     Notificate           = new Notifications();
     _logTable            = new LogBook.Controllers.LogBookController();
     userTable            = new UserTable();
     profileTable         = new ProfileTable();
     listTable            = new ListTable();
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            int    cust_id = Convert.ToInt32(Session["cid"]);
            string profQ   = "SELECT * FROM CUSTOMER WHERE \"customer_id\" =" + cust_id;


            ProfileProtocol.SelectCommand     = profQ;
            ProfileProtocol.SelectCommandType = SqlDataSourceCommandType.Text;
            DataView dv = ProfileProtocol.Select(DataSourceSelectArguments.Empty) as DataView;

            ProfileTable.DataSource   = dv;
            ProfileTable.DataSourceID = null;
            ProfileTable.DataBind();
        }
Beispiel #9
0
 public void Save(ProfileView viewTable)
 {
     if (viewTable.Id == null)
     {
         var domainTable = new ProfileTable();
         Mapper.Map(viewTable, domainTable);
         SaveDomain(domainTable);
     }
     else
     {
         var domainTable = Find(viewTable.Id);
         Mapper.Map(viewTable, domainTable);
         SaveDomain(domainTable);
     }
 }
Beispiel #10
0
    public static void ProfileClickEvent(object obj, EventArgs args)
    {
        ProtoPlayerCharacter player = playerOps.Profile(client);

        if (profileTable == null)
        {
            profileTable = new ProfileTable(player.playerID, player.firstName + " " + player.familyName, player.ownedFiefs, player.location, player.armyID, Convert.ToString(player.purse));
        }
        else
        {
            profileTable.DestroyTable();
            profileTable = new ProfileTable(player.playerID, player.firstName + " " + player.familyName, player.ownedFiefs, player.location, player.armyID, Convert.ToString(player.purse));
        }
        tableLayout.Attach(profileTable.getProfileLayout(), 1, 2, 4, 5);
        myWin.ShowAll();
    }
        private void LoadStoredProfiles()
        {
            try
            {
                storedProfiles = new ProfileTable();
                if (System.IO.File.Exists(ProfileStoragePath))
                {
                    ConfigNode stored = ConfigNode.Load(ProfileStoragePath);
                    if (stored != null && stored.HasNode(STORED_NODE_NAME))
                    {
                        stored = stored.GetNode(STORED_NODE_NAME); // to avoid having an empty cfg, which will cause KSP to hang at load
                        var profiles = stored.GetNodes("PROFILE");

                        foreach (var profileNode in profiles)
                        {
                            try
                            {
                                Profile p = new Profile(profileNode);
                                p.modified = false; // by definition, stored profiles haven't been modified
                                storedProfiles.Add(p.name, p);
                                Log.Normal("[ScienceAlert]Loaded profile '{0}' successfully!", p.name);
                            }
                            catch (Exception e)
                            {
                                Log.Error("ProfileManager: profile '{0}' failed to parse; {1}", name, e);
                            }
                        }
                    }
                }
                if (DefaultProfile == null)
                {
                    storedProfiles.Add("default", Profile.MakeDefault());
                }
            }
            catch (Exception e)
            {
                Log.Error("ProfileManager: Exception loading stored profiles: {0}", e);
                storedProfiles = new ProfileTable();
            }
        }
Beispiel #12
0
        public void SaveDomain(ProfileTable domainTable, string currentUserName = "")
        {
            string          localUserName = getCurrentUserName(currentUserName);
            ApplicationUser user          = _AccountService.FirstOrDefault(x => x.UserName == localUserName);

            if (domainTable.Id == Guid.Empty)
            {
                domainTable.Id                        = Guid.NewGuid();
                domainTable.CreatedDate               = DateTime.UtcNow;
                domainTable.ModifiedDate              = domainTable.CreatedDate;
                domainTable.ApplicationUserCreatedId  = user.Id;
                domainTable.ApplicationUserModifiedId = user.Id;
                repo.Add(domainTable);
            }
            else
            {
                domainTable.ModifiedDate = DateTime.UtcNow;
                domainTable.ApplicationUserModifiedId = user.Id;
                repo.Update(domainTable);
            }
            _uow.Save();
        }
        /// <summary>
        /// Check if username and password is valid, if it is, sets sessions and formauth to true
        /// </summary>
        /// <param name="username">The user name</param>
        /// <param name="password">The User password</param>
        /// <returns>Index View if valid user, Login view if invalid user</returns>
        /// <author>Galaviz Alejos Luis Angel</author>
        public ActionResult Login(string username, string password)
        {
            if (username == "" || password == "")
            {
                this.Redirect("/Login");
            }
            //Check the user on the database
            //usertable = new UserTable();
            BsonDocument doc          = usertable.Login(username, password);
            ProfileTable profiletable = new ProfileTable();

            //If the return is null, is an invalid user


            if (doc != null)
            {
                //User Password time validation
                if (doc["_id"].AsObjectId.ToString() != "52e95ab907719e0d40637d96")
                {
                    JObject userInformation = JsonConvert.DeserializeObject <JObject>(usertable.GetRow(doc["_id"].AsObjectId.ToString()));
                    if (userInformation["lastChgPassword"] != null)
                    {
                        try
                        {
                            DateTime d1 = DateTime.ParseExact(userInformation["lastChgPassword"].ToString(), "dd/MM/yyyy HH:mm:ss", null);
                            DateTime d2 = DateTime.Now;
                            systemSettingsTable = new SystemSettingsTable();

                            JArray cantDays = JsonConvert.DeserializeObject <JArray>(systemSettingsTable.Get("name", "daysChangePassword"));
                            string days     = (from mov in cantDays select(string) mov["days"]).First().ToString();

                            TimeSpan time     = d2 - d1;
                            int      NrOfDays = time.Days;

                            if (int.Parse(days) <= NrOfDays)
                            {
                                ViewBag.Message     = "Timeout";
                                ViewData["timeout"] = "Timeout";

                                List <string> backgrounds = Design.getBackgrounds();
                                return(View("Index", backgrounds));
                            }
                        }
                        catch (Exception ex)
                        {
                            ViewBag.Error       = true;
                            ViewBag.Message     = ex.ToString();
                            ViewData["timeout"] = ex.ToString();
                            List <string> backgrounds = Design.getBackgrounds();
                            return(View("Index", backgrounds));
                        }
                    }
                    else
                    {
                        try
                        {
                            JObject user = JsonConvert.DeserializeObject <JObject>(usertable.GetRow(doc["_id"].AsObjectId.ToString()));
                            user["lastChgPassword"] = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
                            usertable.saveRow(JsonConvert.SerializeObject(user), user["_id"].ToString());
                        }
                        catch (Exception ex)
                        {
                            // throw new Exception(ex.ToString());
                            //return Redirect("~/Home");
                        }
                        //END - User Password time validation
                    }
                }

                DataFileManager Filelimits;
                string          filepath      = "/App_Data/system.conf";
                string          absolutedpath = Server.MapPath(filepath);
                Filelimits = new DataFileManager(absolutedpath, "juanin");

                if (!Filelimits.empty())
                {
                    //Set user name (to show on the upper right corner of the system)
                    this.Session["LoggedUser"] = "";
                    try
                    {
                        this.Session["Semaphores"] = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
                        HttpCookie aCookiesem = new HttpCookie("semaphores");
                        aCookiesem.Value   = Session["Semaphores"].ToString();
                        aCookiesem.Expires = DateTime.Now.AddDays(10);
                        Response.Cookies.Add(aCookiesem);
                    }
                    catch (Exception ex)
                    {
                    }
                    this.Session["Username"] = "";
                    try
                    {
                        this.Session["Username"]    = doc["name"].AsString;
                        this.Session["LoggedUser"] += doc["name"].AsString;
                        try
                        {
                            this.Session["LoggedUser"] += " " + doc["lastname"].AsString;
                        }
                        catch (Exception e) { /*Ignored*/ }
                    }
                    catch (Exception e) { /*Ignored*/ }
                    //If needed for user transactions
                    this.Session["_id"] = doc["_id"].AsObjectId;
                    HttpCookie aCookie2 = new HttpCookie("_id2");
                    aCookie2.Value   = doc["_id"].AsObjectId.ToString();
                    aCookie2.Expires = DateTime.Now.AddDays(10);
                    Response.Cookies.Add(aCookie2);

                    //Check if there exist the image extension registry on database, if it exist, sets the relative
                    //path
                    try
                    {
                        if (!string.IsNullOrEmpty(doc["imgext"].ToString()))
                        {
                            //Relative path to save images
                            string relativepath = string.Format("\\Uploads\\Images\\{0}.{1}",
                                                                Session["_id"].ToString(), doc["imgext"].ToString());

                            //Check if profile picture file exists on the server
                            if (System.IO.File.Exists(Server.MapPath(relativepath)))
                            {
                                //if it exist, sets the profile picture url
                                this.Session["ProfilePicture"] = Url.Content(relativepath);
                                HttpCookie aCookie4 = new HttpCookie("_picture");
                                aCookie4.Value   = Url.Content(relativepath);
                                aCookie4.Expires = DateTime.Now.AddDays(10);
                                Response.Cookies.Add(aCookie4);
                            }
                            else
                            {
                                //Set picture to default
                                this.Session["ProfilePicture"] = null;
                            }
                        }
                    }
                    catch (Exception e) { /*Ignored*/ }

                    string  usuarioid = Session["_id"].ToString();
                    String  profileid = usertable.getRowString(usuarioid);
                    JObject rowArray  = JsonConvert.DeserializeObject <JObject>(profileid);
                    var     jdatos    = "";

                    if (rowArray["permissionsHTK"] != null)
                    {
                        string  arraypermisos = rowArray["permissionsHTK"].ToString();
                        JObject allp          = JsonConvert.DeserializeObject <JObject>(arraypermisos);

                        jdatos = JsonConvert.SerializeObject(allp);
                        this.Session["Permissions"] = jdatos.ToString();
                    }
                    else
                    {
                        string  idpro         = rowArray["profileId"].ToString();
                        String  profiles      = profiletable.GetRow(idpro);
                        JObject rowArraypro   = JsonConvert.DeserializeObject <JObject>(profiles);
                        string  arraypermisos = rowArraypro["permissionsHTK"].ToString();
                        JObject allp          = JsonConvert.DeserializeObject <JObject>(arraypermisos);

                        jdatos = JsonConvert.SerializeObject(allp);

                        this.Session["Permissions"] = jdatos.ToString();
                    }
                    try
                    {
                        this.Session["PermissionsClient"] = Filelimits["scenario"]["modules"].ToString();
                        string     filedata = Filelimits["scenario"]["modules"].ToString();
                        HttpCookie aCookiep = new HttpCookie("permissionsclient");
                        aCookiep.Value   = Filelimits["scenario"]["modules"].ToString();
                        aCookiep.Expires = DateTime.Now.AddDays(10);
                        Response.Cookies.Add(aCookiep);
                    }
                    catch (Exception ex)
                    {
                        this.Session["PermissionsClient"] = "";
                    }
                    HttpCookie aCookie = new HttpCookie("permissions");
                    aCookie.Value   = jdatos.ToString();
                    aCookie.Expires = DateTime.Now.AddDays(10);
                    Response.Cookies.Add(aCookie);

                    HttpCookie aCookie1 = new HttpCookie("_loggeduser");
                    aCookie1.Value   = Session["LoggedUser"].ToString();
                    aCookie1.Expires = DateTime.Now.AddDays(10);
                    Response.Cookies.Add(aCookie1);

                    HttpCookie aCookie3 = new HttpCookie("_username");
                    aCookie3.Value   = Session["Username"].ToString();
                    aCookie3.Expires = DateTime.Now.AddDays(10);
                    Response.Cookies.Add(aCookie3);

                    //Sets the login authorization
                    FormsAuthentication.SetAuthCookie("User", false);
                    TimeSpan time = FormsAuthentication.Timeout;
                    // FormsAuthentication.Timeout.Subtract(time);
                    //Redirect Index
                    FormsAuthentication.Timeout.Subtract(time);

                    /*  TimeSpan time2= TimeSpan.Parse("00:04:00");
                     * FormsAuthentication.Timeout.Add(time2);
                     * string horasuma2 = DateTime.Now.ToString("HH:mm:ss");
                     * TimeSpan timenow = TimeSpan.Parse(horasuma2);
                     * int total = time2.Minutes - timenow.Minutes;*/
                    return(Redirect("~/Home"));
                }
                else
                {
                    ViewBag.Error   = true;
                    ViewBag.Message = "Error de Permisos";
                    List <string> backgrounds = Design.getBackgrounds();

                    return(View("Index", backgrounds));
                }
            }
            else
            {
                //Set error and return to login page
                ViewBag.Error   = true;
                ViewBag.Message = "Error de Login";
                List <string> backgrounds = Design.getBackgrounds();

                return(View("Index", backgrounds));
            }
        }
Beispiel #14
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            if (EntryUserName.Text == null)
            {
                //await this.DisplayAlert(null, "กรุณาระบุชื่อผู้ใช้งาน", null, "ตกลง");
                EntryUserName.PlaceholderColor = Color.FromHex("#ffb3ba");
                EntryUserName.Placeholder      = "กรุณาระบุชื่อผู้ใช้งาน";
                EntryUserName.Focus();
                return;
            }

            if (EntryUserPassword.Text == null)
            {
                //await this.DisplayAlert(null, "กรุณาระบุรหัสผ่าน", null, "ตกลง");
                EntryUserPassword.PlaceholderColor = Color.FromHex("#ffb3ba");
                EntryUserPassword.Placeholder      = "กรุณาระบุรหัสผ่าน";
                EntryUserPassword.Focus();
                return;
            }

            if (EntryUserEmail.Text == null)
            {
                //await this.DisplayAlert(null, "กรุณาระบุรหัสผ่าน", null, "ตกลง");
                EntryUserEmail.PlaceholderColor = Color.FromHex("#ffb3ba");
                EntryUserEmail.Placeholder      = "กรุณาระบุอีเมล์";
                EntryUserEmail.Focus();
                return;
            }

            if (EntryUserPhoneNumber.Text == null)
            {
                //await this.DisplayAlert(null, "กรุณาระบุรหัสผ่าน", null, "ตกลง");
                EntryUserPhoneNumber.PlaceholderColor = Color.FromHex("#ffb3ba");
                EntryUserPhoneNumber.Placeholder      = "กรุณาระบุเบอร์โทรศัพท์";
                EntryUserPhoneNumber.Focus();
                return;
            }

            Device.BeginInvokeOnMainThread(async() => {
                //Register data to firebase also
                var isExist = await apiRequestHelper.RequestCheckUserExistAsync(EntryUserName.Text);
                if (isExist == "true")
                {
                    Toast.MakeText(this.context, "ชื่อผู้ใช้งานซ้ำ", ToastLength.Short).Show();
                    EntryUserName.PlaceholderColor = Color.FromHex("#ffb3ba");
                    EntryUserName.Placeholder      = "กรุณาระบุชื่อผู้ใช้งานใหม่";
                    EntryUserName.Focus();
                    return;
                }

                var dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "UserDatabase.db");
                var db     = new SQLiteConnection(dbpath);
                db.CreateTable <RegUserTable>();

                var item = new RegUserTable()
                {
                    UserName    = EntryUserName.Text,
                    Password    = EntryUserPassword.Text,
                    Email       = EntryUserEmail.Text,
                    PhoneNumber = EntryUserPhoneNumber.Text,
                };

                db.Insert(item);

                var profile = new ProfileTable()
                {
                    UserName    = EntryUserName.Text,
                    Email       = EntryUserEmail.Text,
                    PhoneNumber = EntryUserPhoneNumber.Text,
                };
                db.CreateTable <ProfileTable>();
                db.Insert(profile);


                //Register data to firebase also
                await apiRequestHelper.RequestRegisterUserAsync(EntryUserName.Text, EntryUserPassword.Text, EntryUserEmail.Text, EntryUserPhoneNumber.Text);
                ProfileJson json = new ProfileJson();
                json.UserName    = EntryUserName.Text;
                json.Email       = EntryUserEmail.Text;
                json.PhoneNumber = EntryUserPhoneNumber.Text;
                json.CreateDate  = DateTime.Now.ToString("dd/MM/yyyy hh:mm tt");
                await apiRequestHelper.RequestAddProfileAsync(json);


                var result = await this.DisplayAlert(null, "สมัครสมาชิกสำเร็จ!", null, "ตกลง");

                if (!result)
                {
                    await Navigation.PushAsync(new LoginPage());
                }
            });
        }
Beispiel #15
0
        //private async void SaveProfile(string username, string email)
        private async void SaveProfile(string username)
        {
            RootProfileObject profileData = await apiRequestHelper.RequestProfileAsync(username);

            if (profileData != null && profileData.Data != null && profileData.Data.Count > 0)
            {
                List <ProfileJson> Data = profileData.Data;
                if (Data.Count > 0)
                {
                    ProfileJson json = Data.First <ProfileJson>();

                    var dbpath      = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "UserDatabase.db");
                    var db          = new SQLiteConnection(dbpath);
                    var userprofile = db.GetTableInfo("ProfileTable");

                    if (userprofile.Count == 0)
                    {
                        //TODO เอาข้อมูลจาก Cloud มาอัพเดท Local DB
                        var item = new ProfileTable()
                        {
                            UserName    = username,
                            FirstName   = EntryFirstName.Text,
                            LastName    = EntryLastName.Text,
                            Gender      = ((SelectGender == null || SelectGender.SelectedItem == null)? "" : SelectGender.SelectedItem.ToString()),
                            DateOfBirth = ((SelectDateOfBirth == null || SelectDateOfBirth.Date == null)? "" : SelectDateOfBirth.Date.ToString("dd/MM/yyyy")),
                            Address1    = EntryAddress1.Text,
                            Address2    = EntryAddress2.Text,
                            Address3    = EntryAddress3.Text,
                            Email       = json.Email,
                            PhoneNumber = json.PhoneNumber,
                            Content     = tmpImageBytesNew,

                            CreateDate = DateTime.Now,
                            UpdateDate = DateTime.Now,
                        };
                        db.CreateTable <ProfileTable>();
                        db.Insert(item);

                        //json.UserName = username;
                        json.FirstName = EntryFirstName.Text;
                        json.LastName  = EntryLastName.Text;
                        if (SelectGender != null && SelectGender.SelectedItem != null)
                        {
                            json.Gender = SelectGender.SelectedItem.ToString();
                        }
                        if (SelectDateOfBirth != null && SelectDateOfBirth.Date != null)
                        {
                            json.DateOfBirth = SelectDateOfBirth.Date.ToString("dd/MM/yyyy");
                        }
                        json.Address1 = EntryAddress1.Text;
                        json.Address2 = EntryAddress2.Text;
                        json.Address3 = EntryAddress3.Text;
                        //json.Email = email;
                        //json.PhoneNumber = EntryUserPhoneNumber.Text;
                        //json.CreateDate = DateTime.Now.ToString("dd/MM/yyyy hh:mm tt");
                        json.UpdateDate = DateTime.Now.ToString("dd/MM/yyyy hh:mm tt");

                        await apiRequestHelper.RequestUpdateProfileAsync(json);

                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            Toast.MakeText(context, "บันทึกข้อมูลสำเร็จ", ToastLength.Short).Show();
                        });
                    }
                    else
                    {
                        var item = db.Table <ProfileTable>().Where(u => u.UserName.Equals(username)).FirstOrDefault();

                        if (item != null)
                        {
                            item.FirstName = EntryFirstName.Text;
                            item.LastName  = EntryLastName.Text;
                            if (SelectGender != null && SelectGender.SelectedItem != null)
                            {
                                item.Gender = SelectGender.SelectedItem.ToString();
                            }
                            if (SelectDateOfBirth != null && SelectDateOfBirth.Date != null)
                            {
                                item.DateOfBirth = SelectDateOfBirth.Date.ToString("dd/MM/yyyy");
                            }
                            item.Address1 = EntryAddress1.Text;
                            item.Address2 = EntryAddress2.Text;
                            item.Address3 = EntryAddress3.Text;
                            //item.Email = email;
                            item.PhoneNumber = EntryUserPhoneNumber.Text;

                            if (tmpImageBytesNew != null)
                            {
                                item.Content = tmpImageBytesNew;
                            }
                            item.UpdateDate = DateTime.Now;

                            db.RunInTransaction(() =>
                            {
                                db.Update(item);
                            });

                            json.UserName  = username;
                            json.ProfileId = item.ProfileId.ToString();
                            json.FirstName = EntryFirstName.Text;
                            json.LastName  = EntryLastName.Text;

                            if (SelectGender != null && SelectGender.SelectedItem != null)
                            {
                                json.Gender = SelectGender.SelectedItem.ToString();
                            }
                            if (SelectDateOfBirth != null && SelectDateOfBirth.Date != null)
                            {
                                json.DateOfBirth = SelectDateOfBirth.Date.ToString("dd/MM/yyyy");
                            }
                            json.Address1 = EntryAddress1.Text;
                            json.Address2 = EntryAddress2.Text;
                            json.Address3 = EntryAddress3.Text;
                            //json.Email = email;
                            //json.PhoneNumber = EntryUserPhoneNumber.Text;
                            json.UpdateDate = DateTime.Now.ToString("dd/MM/yyyy hh:mm tt");



                            var result = await apiRequestHelper.RequestUpdateProfileAsync(json);

                            Console.WriteLine("SaveProfile result:", result);

                            Device.BeginInvokeOnMainThread(async() =>
                            {
                                Toast.MakeText(context, "บันทึกข้อมูลสำเร็จ", ToastLength.Short).Show();
                            });
                        }
                        else
                        {
                            //TODO เอาข้อมูลจาก Cloud มาอัพเดท Local DB
                            item = new ProfileTable()
                            {
                                UserName    = username,
                                FirstName   = EntryFirstName.Text,
                                LastName    = EntryLastName.Text,
                                Gender      = ((SelectGender == null || SelectGender.SelectedItem == null) ? "" : SelectGender.SelectedItem.ToString()),
                                DateOfBirth = ((SelectDateOfBirth == null || SelectDateOfBirth.Date == null) ? "" : SelectDateOfBirth.Date.ToString("dd/MM/yyyy")),
                                Address1    = EntryAddress1.Text,
                                Address2    = EntryAddress2.Text,
                                Address3    = EntryAddress3.Text,
                                Email       = json.Email,
                                PhoneNumber = json.PhoneNumber,
                                Content     = tmpImageBytesNew,

                                CreateDate = DateTime.Now,
                                UpdateDate = DateTime.Now,
                            };
                            db.CreateTable <ProfileTable>();
                            db.Insert(item);

                            //json.UserName = username;
                            json.FirstName = EntryFirstName.Text;
                            json.LastName  = EntryLastName.Text;
                            if (SelectGender != null && SelectGender.SelectedItem != null)
                            {
                                json.Gender = SelectGender.SelectedItem.ToString();
                            }
                            if (SelectDateOfBirth != null && SelectDateOfBirth.Date != null)
                            {
                                json.DateOfBirth = SelectDateOfBirth.Date.ToString("dd/MM/yyyy");
                            }
                            json.Address1 = EntryAddress1.Text;
                            json.Address2 = EntryAddress2.Text;
                            json.Address3 = EntryAddress3.Text;
                            //json.Email = email;
                            //json.PhoneNumber = EntryUserPhoneNumber.Text;
                            //json.CreateDate = DateTime.Now.ToString("dd/MM/yyyy hh:mm tt");
                            json.UpdateDate = DateTime.Now.ToString("dd/MM/yyyy hh:mm tt");

                            await apiRequestHelper.RequestUpdateProfileAsync(json);

                            Device.BeginInvokeOnMainThread(async() =>
                            {
                                Toast.MakeText(context, "บันทึกข้อมูลสำเร็จ", ToastLength.Short).Show();
                            });
                        }



                        //Refresh Profile Image
                        var md   = (MasterDetailPage)Application.Current.MainPage;
                        var menu = (MainPageMaster)md.Master;
                        menu.LoadProfile();

                        return;
                    }
                }
            }
        }
 partial void InsertProfileTable(ProfileTable instance);
 partial void UpdateProfileTable(ProfileTable instance);
Beispiel #18
0
        public async void LoadProfile()
        {
            if (Application.Current.Properties.ContainsKey("USER_NAME"))
            {
                var username = Application.Current.Properties["USER_NAME"] as string;
                //Remove codes for retreiving data from local database

                /*
                 * var dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "UserDatabase.db");
                 * var db = new SQLiteConnection(dbpath);
                 * var myquery = db.Table<RegUserTable>().Where(u => u.UserName.Equals(username)).FirstOrDefault();
                 *
                 * if (myquery != null)
                 * {
                 *
                 * }
                 */
                //End of local database

                RootProfileObject profileData = await apiRequestHelper.RequestProfileAsync(username);

                if (profileData != null && profileData.Data != null && profileData.Data.Count > 0)
                {
                    var dbpath       = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "UserDatabase.db");
                    var db           = new SQLiteConnection(dbpath);
                    var profileTable = db.GetTableInfo("ProfileTable");
                    if (profileTable.Count == 0)
                    {
                        List <ProfileJson> Data = profileData.Data;
                        ProfileJson        json = Data.First <ProfileJson>();

                        db.CreateTable <ProfileTable>();
                        ProfileTable item = new ProfileTable()
                        {
                            UserName    = username,
                            FirstName   = json.FirstName,
                            LastName    = json.LastName,
                            Gender      = json.Gender,
                            DateOfBirth = json.DateOfBirth,
                            Address1    = json.Address1,
                            Address2    = json.Address2,
                            Address3    = json.Address3,
                            Email       = json.Email,
                            PhoneNumber = json.PhoneNumber,
                            CreateDate  = DateTime.Now,
                        };
                        db.Insert(item);

                        //
                        string fullName = "";
                        if (item.FirstName != null)
                        {
                            fullName = item.FirstName;
                        }

                        if (item.LastName != null)
                        {
                            fullName += " " + item.LastName;
                        }

                        AccountName.Text = fullName;
                    }
                    else
                    {
                        var profile = db.Table <ProfileTable>().Where(u => u.UserName.Equals(username)).FirstOrDefault();
                        if (profile != null)
                        {
                            string fullName = "";

                            if (profile.FirstName != null)
                            {
                                fullName = profile.FirstName;
                            }

                            if (profile.LastName != null)
                            {
                                fullName += " " + profile.LastName;
                            }

                            AccountName.Text = fullName;

                            if (profile.Content != null)
                            {
                                ImageBytes = profile.Content;
                                Stream sm = BytesToStream(ImageBytes);
                                selectedImage.Source = ImageSource.FromStream(() => sm);
                            }
                        }
                    }
                }
            }
        }
 partial void DeleteProfileTable(ProfileTable instance);
Beispiel #20
0
 public UserProfileController()
 {
     this._profileTable  = new ProfileTable();
     this._userTable     = new UserTable();
     validatepermissions = new validatePermissions();
 }
Beispiel #21
0
        /// <summary>
        /// Load stored profiles from a ConfigNode in the ScienceAlert
        /// directory
        /// </summary>
        private void LoadStoredProfiles()
        {
            try
            {
                storedProfiles = new ProfileTable();

                if (!System.IO.File.Exists(ProfileStoragePath))
                {
                    Log.Warning("ProfileManager: Profile config not found at '{0}'", ProfileStoragePath);
                }
                else
                {
                    Log.Debug("ProfileManager: Loading profile config from '{0}'", ProfileStoragePath);

                    ConfigNode stored = ConfigNode.Load(ProfileStoragePath);

                    if (stored == null || !stored.HasNode(STORED_NODE_NAME))
                    {
                        Log.Error("ProfileManager: Failed to load config");
                    }
                    else
                    {
                        stored = stored.GetNode(STORED_NODE_NAME); // to avoid having an empty cfg, which will
                        // cause KSP to hang at load

                        var profiles = stored.GetNodes("PROFILE");
                        Log.Verbose("Found {0} stored profiles to load", profiles.Length);

                        foreach (var profileNode in profiles)
                        {
                            try
                            {
                                Profile p = new Profile(profileNode);
                                p.modified = false; // by definition, stored profiles haven't been modified

                                storedProfiles.Add(p.name, p);
                                Log.Verbose("Loaded profile '{0}' successfully!", p.name);
                            }
                            catch (Exception e)
                            {
                                Log.Error("ProfileManager: profile '{0}' failed to parse; {1}", name, e);
                            }
                        }
                    }
                }

                // make sure there's a "default" config in there. Ideally the
                // user has created and saved over one but if not, we need
                // at least a default to give to vessels that are missing their
                // profiles
                if (DefaultProfile == null)
                {
                    storedProfiles.Add("default", Profile.MakeDefault());
                }
            } catch (Exception e)
            {
                Log.Error("ProfileManager: Exception loading stored profiles: {0}", e);

                // don't keep anything that might have been loaded; something's
                // gone seriously wrong but we might manage to salvage things if
                // we accept the loss of stored data and use the vessel-specific
                // profiles instead
                storedProfiles = new ProfileTable();
            }
        }
Beispiel #22
0
        //Update or Save Profile Values Field in database
        public HttpResponseMessage ProfileDetails(ProfileModel model)
        {
            //Check Whether Model state is valid or not.
            if (ModelState.IsValid)
            {
                var context = new WebApiEntities();

                //Create object of database Profile Table
                ProfileTable profile = new ProfileTable();

                // Split Token by - sign
                string[] tokenArray = model.GenToken.Split('-');

                // Get ID value by third element of tokenArray
                string ID = tokenArray[3];

                //convert string DOB into DateTime
                string inString = model.DOB;

                DateTime dateValue;
                if (!DateTime.TryParse(inString, out dateValue))
                {
                    Request.CreateErrorResponse(HttpStatusCode.PartialContent, "Please fill correct date of birth");
                }

                //Update profile Data for Existing User
                if (context.ProfileTables.Any(user => user.UserID.ToString() == ID))
                {
                    //Query Statement for Specific ID
                    var query = from user in context.ProfileTables where ID == user.UserID.ToString() select user.ID;
                    //Update Values
                    profile.FirstName = model.Fname;
                    profile.LastName  = model.Lname;
                    profile.DOB       = dateValue;
                    profile.UserID    = Convert.ToInt32(ID);
                    profile.Language  = model.Language;
                    profile.ID        = query.First();

                    context.ProfileTables.Attach(profile);
                    context.Entry(profile).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();

                    //Return Message Profile Update with Ok status
                    return(Request.CreateResponse(HttpStatusCode.OK, "Profile Updated"));
                }
                // Create New Profile data for New User
                else
                {
                    //Save new user value into database
                    profile.UserID    = Convert.ToInt32(ID);
                    profile.FirstName = model.Fname;
                    profile.LastName  = model.Lname;
                    profile.DOB       = dateValue;
                    profile.Language  = model.Language;

                    context.ProfileTables.Add(profile);
                    context.SaveChanges();

                    //Return Message Profile Save with Ok status
                    return(Request.CreateResponse(HttpStatusCode.OK, "Profile Save"));
                }
            }
            // Create Error Response with Bad Request. and send message please fill again to client
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "please Fill again"));
        }
Beispiel #23
0
        async void Login_Clicked(object sender, EventArgs e)
        {
            if (EntryUser.Text == null)
            {
                //await this.DisplayAlert(null, "กรุณาระบุชื่อผู้ใช้งาน", null, "ตกลง");
                EntryUser.PlaceholderColor = Color.FromHex("#ffb3ba");
                EntryUser.Placeholder      = "กรุณาระบุชื่อผู้ใช้งาน";
                EntryUser.Focus();
                return;
            }

            if (EntryPassword.Text == null)
            {
                //await this.DisplayAlert(null, "กรุณาระบุรหัสผ่าน", null, "ตกลง");
                EntryPassword.PlaceholderColor = Color.FromHex("#ffb3ba");
                EntryPassword.Placeholder      = "กรุณาระบุรหัสผ่าน";
                EntryPassword.Focus();
                return;
            }

            btnLogin.IsEnabled = false;
            //Cloud database
            //Register data to firebase also
            RegUserJson user = await apiRequestHelper.RequestLoginUserAsync(EntryUser.Text, EntryPassword.Text);

            if (user != null & user.UserName == EntryUser.Text)
            {
                var dbpath  = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "UserDatabase.db");
                var db      = new SQLiteConnection(dbpath);
                var reguser = db.GetTableInfo("RegUserTable");
                if (reguser.Count == 0)
                {
                    db.CreateTable <RegUserTable>();

                    var item = new RegUserTable()
                    {
                        UserName    = user.UserName,
                        Password    = user.Password,
                        Email       = user.Email,
                        PhoneNumber = user.PhoneNumber,
                    };

                    db.Insert(item);
                }
                else
                {
                    var item = db.Table <RegUserTable>().Where(u => u.UserName.Equals(user.UserName)).FirstOrDefault();

                    if (item == null)
                    {
                        var data = new RegUserTable()
                        {
                            UserName    = user.UserName,
                            Password    = user.Password,
                            Email       = user.Email,
                            PhoneNumber = user.PhoneNumber,
                        };
                        db.Insert(data);
                    }
                }
                RootProfileObject profileData = await apiRequestHelper.RequestProfileAsync(user.UserName);

                if (profileData != null && profileData.Data != null && profileData.Data.Count > 0)
                {
                    List <ProfileJson> Data = profileData.Data;
                    if (Data.Count > 0)
                    {
                        ProfileJson json = Data.First <ProfileJson>();

                        var userprofile = db.GetTableInfo("ProfileTable");
                        if (userprofile.Count == 0)
                        {
                            db.CreateTable <ProfileTable>();
                            var profile = new ProfileTable()
                            {
                                UserName    = json.UserName,
                                FirstName   = json.FirstName,
                                LastName    = json.LastName,
                                Gender      = (json.Gender == null ? "" : json.Gender),
                                DateOfBirth = (json.DateOfBirth == null ? "" : json.DateOfBirth),
                                Address1    = json.Address1 == null? "" : json.Address1,
                                Address2    = json.Address2 == null ? "" : json.Address2,
                                Address3    = json.Address3 == null ? "" : json.Address3,
                                Email       = json.Email,
                                PhoneNumber = json.PhoneNumber,

                                CreateDate = DateTime.Now,
                                UpdateDate = DateTime.Now,
                            };

                            db.Insert(profile);
                        }
                        else
                        {
                            var item = db.Table <ProfileTable>().Where(u => u.UserName.Equals(user.UserName)).FirstOrDefault();

                            if (item == null)
                            {
                                var profile = new ProfileTable()
                                {
                                    UserName    = json.UserName,
                                    FirstName   = json.FirstName,
                                    LastName    = json.LastName,
                                    Gender      = (json.Gender == null ? "" : json.Gender),
                                    DateOfBirth = (json.DateOfBirth == null ? "" : json.DateOfBirth),
                                    Address1    = json.Address1 == null ? "" : json.Address1,
                                    Address2    = json.Address2 == null ? "" : json.Address2,
                                    Address3    = json.Address3 == null ? "" : json.Address3,
                                    Email       = json.Email,
                                    PhoneNumber = json.PhoneNumber,

                                    CreateDate = DateTime.Now,
                                    UpdateDate = DateTime.Now,
                                };

                                db.Insert(profile);
                            }
                        }
                    }
                }

                ///////////////////

                Device.StartTimer(TimeSpan.FromSeconds(0.1), () => {
                    btnLogin.IsEnabled = true;

                    Toast.MakeText(context, "Login Successfull", ToastLength.Short).Show();
                    Application.Current.Properties.Add("USER_NAME", EntryUser.Text);
                    App.Current.MainPage = new MainPage();
                    return(false);
                });
            }
            else
            {
                Device.BeginInvokeOnMainThread(async() =>
                {
                    var result2 = await this.DisplayAlert(null, "ข้อผิดพลาด! ไม่พบข้อมูลผู้ใช้งาน\nกรุณาตรวจสอบชื่อผู้ใช้งานและรหัสผ่าน", null, "ตกลง");

                    if (!result2)
                    {
                        btnLogin.IsEnabled = true;
                        EntryUser.Focus();
                    }
                });
            }

            //End of Cloud database


            //Local database

            /*
             * var dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "UserDatabase.db");
             * var db = new SQLiteConnection(dbpath);
             * db.CreateTable<RegUserTable>();
             * var myquery = db.Table<RegUserTable>().Where(u => u.UserName.Equals(EntryUser.Text) && u.Password.Equals(EntryPassword.Text)).FirstOrDefault();
             *
             * if (myquery != null)
             * {
             *  Application.Current.Properties.Add("USER_NAME", myquery.UserName);
             *  App.Current.MainPage = new MainPage();
             * }
             * else
             * {
             *  Device.BeginInvokeOnMainThread(async () => {
             *      if(EntryUser.Text == null)
             *      {
             *          //await this.DisplayAlert(null, "กรุณาระบุชื่อผู้ใช้งาน", null, "ตกลง");
             *          EntryUser.PlaceholderColor = Color.FromHex("#ffb3ba");
             *          EntryUser.Placeholder = "กรุณาระบุชื่อผู้ใช้งาน";
             *          EntryUser.Focus();
             *          return;
             *      }
             *
             *      if (EntryPassword.Text == null)
             *      {
             *          //await this.DisplayAlert(null, "กรุณาระบุรหัสผ่าน", null, "ตกลง");
             *          EntryPassword.PlaceholderColor = Color.FromHex("#ffb3ba");
             *          EntryPassword.Placeholder = "กรุณาระบุรหัสผ่าน";
             *          EntryPassword.Focus();
             *          return;
             *      }
             *
             *      var result = await this.DisplayAlert(null, "ข้อผิดพลาด! ไม่พบข้อมูลผู้ใช้งาน\nกรุณาตรวจสอบชื่อผู้ใช้งานและรหัสผ่าน", null, "ตกลง");
             *
             *      if (!result)
             *      {
             *          EntryUser.Focus();
             *      }
             *  });
             *
             * }
             */
            //End of Local database
        }