Esempio n. 1
0
        private async Task UpdateHairSalon()
        {
            if (ValidateInputs())
            {
                HairSalonEditVM hairSalonEditVM = new HairSalonEditVM()
                {
                    Id          = hairSalon.Id,
                    Name        = TbName.Text,
                    Description = TbDescription.Text,
                    Address     = TbAddress.Text,
                    City        = TbCity.Text,
                    Country     = (Country)CbCountries.SelectedItem,
                    OwnerId     = hairSalon.OwnerId
                };

                ls.LblLoading.Text = "Editing";
                ls.Show();
                bool success = await hairSalonApi.UpdateHairSalon(hairSalonEditVM);

                ls.Close();

                if (success)
                {
                    Close();
                }
                else
                {
                    MessageBox.Show("Fail");
                }
            }
            else
            {
                MessageBox.Show("All input fields are required");
            }
        }
Esempio n. 2
0
        public async Task <bool> UpdateHairSalon(HairSalonEditVM hairSalonEditVM)
        {
            StringContent       content  = GetStringContent(hairSalonEditVM);
            HttpClient          request  = new HttpClient();
            HttpResponseMessage response = await request.PutAsync($"{ API_URL }/EditHairSalon", content);

            if (response.IsSuccessStatusCode)
            {
                bool result = await response.Content.ReadAsAsync <bool>();

                return(result);
            }
            return(false);
        }
Esempio n. 3
0
        public bool EditHairSalon(HairSalonEditVM hairSalonEditVM)
        {
            Owner owner = unitOfWork.Owners.Get(hairSalonEditVM.OwnerId);

            string  inputAddress  = hairSalonEditVM.Address;
            string  inputCityName = hairSalonEditVM.City;
            Country inputCountry  = hairSalonEditVM.Country;

            Country country = unitOfWork.Countries.Get(inputCountry.Id);

            bool cityExists = unitOfWork.Cities.Exists(inputCityName, country.Id);

            City city = cityExists ?
                        unitOfWork.Cities.GetCityWithCountry(inputCityName, country.Id) :
                        new City()
            {
                Name = inputCityName, Country = country
            };

            bool locationExists = unitOfWork.Locations.Exists(inputAddress, city.Id, city.Country.Id);

            DataAccessLayer.Models.Location location = locationExists ?
                                                       unitOfWork.Locations.GetLocationWithCity(inputAddress, city.Id, city.Country.Id) :
                                                       new DataAccessLayer.Models.Location()
            {
                Address = inputAddress, City = city
            };

            HairSalon hairSalon = unitOfWork.HairSalons.Get(hairSalonEditVM.Id);

            hairSalon.Name        = hairSalonEditVM.Name;
            hairSalon.Description = hairSalonEditVM.Description;
            hairSalon.Location    = location;
            hairSalon.Owner       = owner;

            int success = unitOfWork.Complete();

            return(success > 0);
        }