Example #1
0
        public async Task<ActionResult> AddEditListing(int id = 0)
        {
            var listingViewModel = new ListingViewModel();
            ContactViewModel listingContact = new ContactViewModel();
            listingContact.ContactNo = 9988765432;
            listingContact.ContactTypeId = (int)ListingContactType.Landline;
            listingViewModel.ListingContacts.Contacts.Add(listingContact);
            listingViewModel.ActionName = "AddEditListing";
            listingViewModel.ControllerName = "Vendor";
            listingViewModel.FormId = "listingForm";
            listingViewModel.FormSuccessCallBack = "addEditListing.onAddEditListingSuccessCallBack";
            var client = TMCHttpClient.GetClient(User.AccessToken());
            if (id > 0)
            {
                HttpResponseMessage contentResponse = await client.GetAsync("api/listing/" + id);
                if (contentResponse.IsSuccessStatusCode)
                {
                    string content = await contentResponse.Content.ReadAsStringAsync();
                    var cotentResult = JsonConvert.DeserializeObject<ListingViewModel>(content);
                    listingViewModel = cotentResult;
                }
                else
                {
                    return Content("An error occurred while fetching the data.");
                }
                
                //listing contacts
                HttpResponseMessage contentContactsResponse = await client.GetAsync("api/listing/" + id+"/contacts");
                if (contentContactsResponse.IsSuccessStatusCode)
                {
                    string content = await contentContactsResponse.Content.ReadAsStringAsync();
                    var cotentResult = JsonConvert.DeserializeObject<ListingViewModel>(content);
                    listingViewModel.ListingContacts = cotentResult.ListingContacts;
                }
            }



            //listing category 
            listingViewModel.ListingCategories.CategorySaytListing = new CategorySaytViewModel();
            listingViewModel.ListingCategories.CategorySaytListing.ControlId = "ddlAddCategories";
            //todo get the url from here 
            //listingViewModel.ListingCategories.CategorySaytListing.AjaxGetUrl = "";
            listingViewModel.ListingCategories.CategorySaytListing.HtmlFieldPrefix = "CategorySaytHome";
            listingViewModel.ListingCategories.CategorySaytListing.SelectCallBack = "addEditListing.onSelectedCategoryCallBack"; 

            //listing Service Area
            listingViewModel.ListingServiceLocations.CitySaytListing = new CitySaytViewModel();
            listingViewModel.ListingServiceLocations.CitySaytListing.ControlId = "ddlAddCities"; 
            listingViewModel.ListingServiceLocations.CitySaytListing.HtmlFieldPrefix = "CirySaytListingServiceArea";
            listingViewModel.ListingServiceLocations.CitySaytListing.SelectCallBack = "addEditListing.onSelectedAddCityCallBack"; 
           //todo sometimes the city api call it was going to make is like this vendor/api/coty/{searchStr} so breaks , need to have a look
            // listingViewModel.ListingServiceLocations.CitySaytListing.AjaxGetUrl 
           //     = Url.RouteUrl("DefaultApi", new { httproute="", controller="city"  }); 


            return View("AddEditListing", listingViewModel);
        }
 public IHttpActionResult GetListingContacts(int id)
 {
     var listingFacade = (IListingFacade)FacadeFactory.Instance.Create(FacadeType.Listing);
     var listingResult = listingFacade.GetContactsByListingId(id);
     var listingViewModel = new ListingViewModel();
     if (listingResult.IsValid() && listingResult.Data.ListingContacts != null)
     {
         foreach (var listingContact in listingResult.Data.ListingContacts.Contacts)
         {
             var listingContactViewModel = new ContactViewModel();
             DTOConverter.FillViewModelFromDTO(listingContactViewModel, listingContact);
             listingViewModel.ListingContacts.Contacts.Add(listingContactViewModel);
         }
     }
     return Ok(listingViewModel);
 }
 public ListingContactsViewModel()
 {
     Contacts = new List<ContactViewModel>();
     NewContact = new ContactViewModel();
 }