Example #1
0
        /// <summary>
        /// 构造函数
        /// </summary>
        public MyDetialViewModel()
        {
            snackbar = new SnackbarMessageQueue();
            GenderList.Clear();
            GenderList.Add("女");
            GenderList.Add("男");
            InitialCommands();

            #region Register Messenger
            Messenger.Default.Register <bool>(this, UserDetailNotifications.ShowMyDetial, (value) =>
            {
                LoadDetials();
            });
            #endregion
        }
        public void loadLists(MerkatoDbContext context)
        {
            SelectListItem all = new SelectListItem()
            {
                Text = "(All)", Value = "0"
            };

            ClientList = context.Client.Select(p => new SelectListItem()
            {
                Text = p.ClientName, Value = p.Id.ToString()
            }).ToList();
            OutletList = context.Outlet.Select(p => new SelectListItem()
            {
                Text = p.Name, Value = p.Id.ToString()
            }).ToList();
            GenderList = context.Gender.Select(p => new SelectListItem()
            {
                Text = p.Name, Value = p.Id.ToString()
            }).ToList();
            GenderList.Add(all);
            SkillsList = context.SkillsProficiency.Select(p => new SelectListItem()
            {
                Text = p.Name, Value = p.Id.ToString()
            }).ToList();
            SkillsList.Add(all);
            LanguageList = context.LanguageProficiency.Select(p => new SelectListItem()
            {
                Text = p.Name, Value = p.Id.ToString()
            }).ToList();
            LanguageList.Add(all);
            GradeList = context.AgentGrade.Select(p => new SelectListItem()
            {
                Text = p.Name, Value = p.Id.ToString()
            }).ToList();
            GradeList.Add(all);

            var query = (from PM in context.ProductMechanism
                         join M in context.Mechanism on PM.MechanismId equals M.Id
                         select new { ProductMechanism = PM, Mechanism = M })
                        .Select(p => new MechanismModel {
                Name = p.Mechanism.Name, Id = p.ProductMechanism.MechanismId
            }).ToList();

            MechanismList = query.Select(p => new SelectListItem()
            {
                Text = p.Name, Value = p.Id.ToString()
            }).ToList();
        }
Example #3
0
        private void initPicker()
        {
            GenderList.Add(new Gender {
                Val = 1, Name = "男"
            });
            GenderList.Add(new Gender {
                Val = 0, Name = "女"
            });

            PayMethodList.Add(new PayMethod {
                Val = 1, Name = "推薦人代收"
            });
            PayMethodList.Add(new PayMethod {
                Val = 0, Name = "自行繳費"
            });
        }
Example #4
0
        private void InitializeDemoData()
        {
            var male = new GenderModel()
            {
                Id = 1, Gender = "MALE"
            };
            var female = new GenderModel()
            {
                Id = 2, Gender = "FEMALE"
            };
            var unknown = new GenderModel()
            {
                Id = 3, Gender = "UNKNOWN"
            };

            GenderList.Add(male);
            GenderList.Add(female);
            GenderList.Add(unknown);
        }
Example #5
0
        private void BtnInsert_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (ScreenMode.Location == screenmode)
                {
                    if (string.IsNullOrEmpty(txtDescription.Text))
                    {
                        throw new Exception("Please enter a location");
                    }

                    Location location = new Location();

                    if (locations.Any(l => l.Description == txtDescription.Text))
                    {
                        throw new Exception("This location has already exists.");
                    }
                    else
                    {
                        location.Description = txtDescription.Text;
                    }

                    //Send it to the API
                    HttpClient client             = InitializeClient();
                    string     serializedLocation = JsonConvert.SerializeObject(location);
                    var        content            = new StringContent(serializedLocation);
                    content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                    HttpResponseMessage response = client.PostAsync("Location", content).Result;

                    if (response.StatusCode == System.Net.HttpStatusCode.OK || response.StatusCode == System.Net.HttpStatusCode.NoContent)
                    {
                        //Get the new location Id
                        response = client.GetAsync("Location?description=" + location.Description).Result;
                        string   result            = response.Content.ReadAsStringAsync().Result;
                        Location retrievedLocation = JsonConvert.DeserializeObject <Location>(result);

                        //Save the Id so that we can update it.
                        location.Id = retrievedLocation.Id;

                        locations.Add(location);
                        Rebind();

                        //Select the inserted location
                        cboAttribute.SelectedIndex = locations.FindIndex(p => p == location);
                    }
                    else
                    {
                        throw new Exception("Location could not be inserted");
                    }
                }
                else if (ScreenMode.Gender == screenmode)
                {
                    if (string.IsNullOrEmpty(txtDescription.Text))
                    {
                        throw new Exception("Please enter a gender");
                    }

                    Gender gender = new Gender();

                    if (genders.Any(l => l.Description == txtDescription.Text))
                    {
                        throw new Exception("This gender has already exists.");
                    }
                    else
                    {
                        gender.Description = txtDescription.Text;
                    }

                    //Send it to the API
                    HttpClient client           = InitializeClient();
                    string     serializedGender = JsonConvert.SerializeObject(gender);
                    var        content          = new StringContent(serializedGender);
                    content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                    HttpResponseMessage response = client.PostAsync("Gender", content).Result;

                    if (response.StatusCode == System.Net.HttpStatusCode.OK || response.StatusCode == System.Net.HttpStatusCode.NoContent)
                    {
                        //Get the new location Id
                        response = client.GetAsync("Gender?description=" + gender.Description).Result;
                        string result          = response.Content.ReadAsStringAsync().Result;
                        Gender retrievedGender = JsonConvert.DeserializeObject <Gender>(result);

                        //Save the Id so that we can update it.
                        gender.Id = retrievedGender.Id;

                        genders.Add(gender);
                        Rebind();

                        //Select the inserted location
                        cboAttribute.SelectedIndex = genders.FindIndex(p => p == gender);
                    }
                    else
                    {
                        throw new Exception("Gender could not be inserted");
                    }
                }
                else if (ScreenMode.Race == screenmode)
                {
                    if (string.IsNullOrEmpty(txtDescription.Text))
                    {
                        throw new Exception("Please enter a race");
                    }

                    Race race = new Race();

                    if (races.Any(l => l.Description == txtDescription.Text))
                    {
                        throw new Exception("This race has already exists.");
                    }
                    else
                    {
                        race.Description = txtDescription.Text;
                    }

                    //Send it to the API
                    HttpClient client         = InitializeClient();
                    string     serializedRace = JsonConvert.SerializeObject(race);
                    var        content        = new StringContent(serializedRace);
                    content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                    HttpResponseMessage response = client.PostAsync("Race", content).Result;

                    if (response.StatusCode == System.Net.HttpStatusCode.OK || response.StatusCode == System.Net.HttpStatusCode.NoContent)
                    {
                        //Get the new location Id
                        response = client.GetAsync("Race?description=" + race.Description).Result;
                        string result        = response.Content.ReadAsStringAsync().Result;
                        Race   retrievedRace = JsonConvert.DeserializeObject <Race>(result);

                        //Save the Id so that we can update it.
                        race.Id = retrievedRace.Id;


                        races.Add(race);
                        Rebind();


                        //Select the inserted location
                        cboAttribute.SelectedIndex = races.FindIndex(p => p == race);
                    }
                    else
                    {
                        throw new Exception("Race could not be inserted");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!");
            }
        }