Ejemplo n.º 1
0
        private async Task OnSaveElection(object p)
        {
            IMapper       mapper = Utils.CreateMapper();
            List <string> errors = new List <string>();

            if (string.IsNullOrEmpty(Description))
            {
                errors.Add("Description is required.");
            }
            if (errors.Count > 0)
            {
                string msg = string.Join("\n", errors.ToList());
                MessageBox.Show("Errors", msg);
                return;
            }

            List <CategoryViewModel> cvmList = CategoryList.Where(n => n.Delete).ToList();

            ElectionModels.Election election = mapper.Map <ElectionViewModel, ElectionModels.Election>(this);

            List <Category> catlist = election.CategoryList.Where(n => n.Delete).ToList();

            //List<Party> plist = mapper.Map<List<PartyViewModel>, List<Party>>(Partys.ToList());
            election.PartyList = DataService.Partys;
            ElectionModels.Election result = await DataService.PostElection(election);

            if (result != null)
            {
                RemoveDeletedRecords();
            }
        }
Ejemplo n.º 2
0
        public static async Task <ElectionModels.Election> PostElection(ElectionModels.Election election)
        {
            if (election == null)
            {
                return(null);
            }

            using (client = new HttpClient())
            {
                string url  = string.Format(@"{0}/Election", electionUrl);
                var    json = JsonConvert.SerializeObject(election);
                var    data = new StringContent(json, Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PostAsync(url, data);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    // this returns all categorys, and tickets in the election Object!
                    election = JsonConvert.DeserializeObject <ElectionModels.Election>(await response.Content.ReadAsStringAsync());
                    return(Election);
                }
                else
                {
                    Debug.WriteLine(response.StatusCode);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
 public void InitializeElection(ElectionModels.Election election)
 {
     if (election != null)
     {
         IMapper mapper = Utils.CreateMapper();
         mapper.Map <ElectionModels.Election, ElectionViewModel>(election, this);
         CategoryTypes        = Utils.CategoryTypes();
         SelectedCategoryType = CategoryTypes.SingleOrDefault(n => n.Id == (int)CategoryTypeEnum.measure);
         HasLoaded            = true;
     }
 }