Пример #1
0
        public async Task <IActionResult> OnPostLocationTemplate()
        {
            try
            {
                if (ModelState.IsValid)
                {
                    LocationTemplate_Dto location = JsonSerializer.Deserialize <LocationTemplate_Dto>(Request.Form["info"]);
                    LocationAddress      address  = JsonSerializer.Deserialize <LocationAddress>(Request.Form["address"]);
                    location.SetProperty("address", address);

                    bool IsEditing = location.Id != Guid.Empty;
                    if (IsEditing)
                    {
                        LocationTemplate curLocation = await LocationTemplateAppService.Repository.GetAsync(location.Id);

                        curLocation.LocationName          = location.LocationName;
                        curLocation.LocationNameLocalized = location.LocationNameLocalized;
                        curLocation.LocationCode          = location.LocationCode;
                        curLocation.Status            = location.Status;
                        curLocation.LocationCountryId = location.LocationCountryId;
                        curLocation.LocationEmail     = location.LocationEmail;
                        curLocation.LocationFax       = location.LocationFax;
                        curLocation.LocationMobile    = location.LocationMobile;
                        curLocation.LocationPhone     = location.LocationPhone;

                        curLocation.LocationCountry = null;
                        curLocation.UpdateExtraProperties(location.ExtraProperties);

                        LocationTemplate_Dto updated = ObjectMapper.Map <LocationTemplate, LocationTemplate_Dto>(await LocationTemplateAppService.Repository.UpdateAsync(curLocation));
                        updated.LocationCountry = ObjectMapper.Map <DictionaryValue, DictionaryValue_Dto>(await DictionaryValuesRepo.GetAsync(x => x.Id == updated.LocationCountryId));

                        return(StatusCode(200, updated));
                    }
                    else
                    {
                        location.Id = Guid.Empty;

                        LocationTemplate_Dto added = await LocationTemplateAppService.CreateAsync(location);

                        added.LocationCountry = ObjectMapper.Map <DictionaryValue, DictionaryValue_Dto>(await DictionaryValuesRepo.GetAsync(x => x.Id == added.LocationCountryId));
                        return(StatusCode(200, added));
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(StatusCode(500));
        }
Пример #2
0
        public async Task <IActionResult> OnDeleteLocation()
        {
            List <LocationTemplate_Dto> locations = JsonSerializer.Deserialize <List <LocationTemplate_Dto> >(Request.Form["locations"]);

            try
            {
                for (int i = 0; i < locations.Count; i++)
                {
                    LocationTemplate_Dto location = locations[i];
                    await LocationTemplateAppService.DeleteAsync(location.Id);
                }
                return(StatusCode(200));
            }
            catch (Exception ex)
            {
                return(StatusCode(500));
            }
        }