private void ProcessForm()
        {
            GymDTO itemToSave = new GymDTO();
            string serviceURL = _baseServiceURI + "Gym/Item/";

            //string gymId = HiddenGymId.Value;
            if (HiddenGymId.Value.ToInt() > 0)
            {
                itemToSave.Id = HiddenGymId.Value.ToInt();
            }

            itemToSave.Name         = txtGymName.Text.Trim();
            itemToSave.Abbreviation = txtGymAbbreviation.Text.Trim();
            itemToSave.WebSite      = txtWebsite.Text.Trim();
            itemToSave.Description  = txtDescription.Text.Trim();
            //itemToSave.CreateDate = txtCreateDate.Text.ToDate();

            using (HttpClient httpClient = new HttpClient())
            {
                using (HttpResponseMessage responseMessage = httpClient.PutAsJsonAsync(serviceURL, itemToSave).Result)
                {
                    if (responseMessage.IsSuccessStatusCode)
                    {
                        this.ReloadPage();
                    }
                    else
                    {
                        this.DisplayLocalMessage("There was an error saving this Gym record");
                    }
                }
            }
        }
Esempio n. 2
0
        private Gym DTOItemToGym(GymDTO gymDTO)
        {
            Gym tempItem = new Gym();

            if (gymDTO != null)
            {
                tempItem.GymId = gymDTO.Id;

                if (!string.IsNullOrEmpty(gymDTO.Name))
                {
                    tempItem.GymName = gymDTO.Name;
                }

                if (!string.IsNullOrEmpty(gymDTO.Abbreviation))
                {
                    tempItem.Abbreviation = gymDTO.Abbreviation;
                }

                if (!string.IsNullOrEmpty(gymDTO.WebSite))
                {
                    tempItem.WebSite = gymDTO.WebSite;
                }

                if (!string.IsNullOrEmpty(gymDTO.Description))
                {
                    tempItem.Description = gymDTO.Description;
                }

                //if ((!string.IsNullOrEmpty(gymDTO.CreateDate.ToShortDateString())))
                //    tempItem.CreateDate = gymDTO.CreateDate;
            }
            return(tempItem);
        }
Esempio n. 3
0
        private GymDTO GymItemToDTO(Gym gymModel)
        {
            GymDTO tempItem = new GymDTO();

            if (gymModel != null)
            {
                tempItem.Id = gymModel.GymId;

                if (!string.IsNullOrEmpty(gymModel.GymName))
                {
                    tempItem.Name = gymModel.GymName;
                }

                if (!string.IsNullOrEmpty(gymModel.Abbreviation))
                {
                    tempItem.Abbreviation = gymModel.Abbreviation;
                }

                if (!string.IsNullOrEmpty(gymModel.WebSite))
                {
                    tempItem.WebSite = gymModel.WebSite;
                }

                if (!string.IsNullOrEmpty(gymModel.Description))
                {
                    tempItem.Description = gymModel.Description;
                }

                //if (!string.IsNullOrEmpty(gymModel.CreateDate.ToShortDateString()))
                //    tempItem.CreateDate = gymModel.CreateDate;
            }
            return(tempItem);
        }
Esempio n. 4
0
        public GymDTO SaveGym(GymDTO gymToSave)
        {
            int gymId = GymManager.Save(this.DTOItemToGym(gymToSave));

            // Gym updatedItem = GymManager.GetItem(gymId);

            gymToSave.Id = gymId;
            return(gymToSave);


            //return this.GymItemToDTO(updatedItem);
        }
        protected void GymList_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                GymDTO gymItem = (GymDTO)e.Item.DataItem;

                LinkButton editButton   = (LinkButton)e.Item.FindControl("EditButton");
                LinkButton deleteButton = (LinkButton)e.Item.FindControl("DeleteButton");

                editButton.CommandArgument   = gymItem.Id.ToString();
                deleteButton.CommandArgument = gymItem.Id.ToString();
            }
        }
        private void BindUpdateInfo(int gymId)
        {
            using (WebClient webClient = new WebClient())
            {
                string json         = webClient.DownloadString(_baseServiceURI + "Gym/Item/" + gymId.ToString());
                GymDTO itemToUpdate = base.GetModelItem <GymDTO>(json);

                if (itemToUpdate != null)
                {
                    HiddenGymId.Value = itemToUpdate.Id.ToString();

                    if (!string.IsNullOrEmpty(itemToUpdate.Name))
                    {
                        txtGymName.Text = itemToUpdate.Name;
                    }

                    if (!string.IsNullOrEmpty(itemToUpdate.Abbreviation))
                    {
                        txtGymAbbreviation.Text = itemToUpdate.Abbreviation;
                    }

                    if (!string.IsNullOrEmpty(itemToUpdate.WebSite))
                    {
                        txtWebsite.Text = itemToUpdate.WebSite;
                    }

                    if (!string.IsNullOrEmpty(itemToUpdate.Description))
                    {
                        txtDescription.Text = itemToUpdate.Description;
                    }

                    //if (itemToUpdate.CreateDate != DateTime.MinValue)
                    //    txtCreateDate.Text = itemToUpdate.CreateDate.ToShortDateString();


                    SaveButton.Text = "Update Gym";

                    btnCancel.Visible = true;
                }
                else
                {
                    this.DisplayLocalMessage("Update failed. Couldn't find Gym record.");
                }
            }
        }