Exemplo n.º 1
0
 public  async Task<ActionResult>  Index()
 {
     var client = TMCHttpClient.GetClient();
     var userId = 3;
     HttpResponseMessage egsResponse = await client.GetAsync("api/listing/GetListingsByUserId/" + userId);//todo
     List<ListingViewModel> listingViewModels = new List<ListingViewModel>();
     if (egsResponse.IsSuccessStatusCode)
     {
         string egsContent = await egsResponse.Content.ReadAsStringAsync();
         var lstExpenseGroupStatusses = JsonConvert.DeserializeObject<List<ListingViewModel>>(egsContent);
         listingViewModels = lstExpenseGroupStatusses;
     }
     else
     {
         return Content("An error occurred.");
     }
    UserViewModel userViewModel = new UserViewModel();
     userViewModel.FirstName = "Mahi";
     userViewModel.LastName = "Kumar";
     userViewModel.Email = "*****@*****.**";
     userViewModel.AddressLine1 = "Palam Vihar";
     userViewModel.Listings = listingViewModels;
     
     return View(userViewModel);
 }
Exemplo n.º 2
0
        public System.Web.Http.IHttpActionResult Get(int id, string fields = null)
        {
            var listingFacade = (IListingFacade)FacadeFactory.Instance.Create(FacadeType.Listing);
            var userFacade = (IUserFacade)FacadeFactory.Instance.Create(FacadeType.User);
            var vendorResult = userFacade.GetUserById(1); //todo
            var vendorViewModel = new UserViewModel();
            if (vendorResult.IsValid())
            {
                //todo check if the data is valid
                var listingViewModel = new ListingViewModel();

               // var listingResult = listingFacade.GetlistingById(1);// todo

                // DTOConverter.FillViewModelFromDTO(listingViewModel, listingResult.Data );
               // DTOConverter.FillViewModelFromDTO(vendorViewModel, vendorResult.Data);
                vendorViewModel.AddressLine1 = vendorResult.Data.AddressLine1;
                vendorViewModel.AddressLine2 = vendorResult.Data.AddressLine2;
                vendorViewModel.UserName = vendorResult.Data.UserName;
                vendorViewModel.FirstName = vendorResult.Data.FirstName;
               // listingViewModel.Owner = vendorViewModel;
            }

            return Ok(vendorViewModel);
        }
Exemplo n.º 3
0
        public async Task<ActionResult> Register(RegisterViewModel userModel)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName = userModel.MobileNo,
                    FirstName = userModel.FirstName,
                    LastName = userModel.LastName,
                    Email = userModel.Email,
                    MobileNo = userModel.MobileNo
                };
                var result = await UserManager.CreateAsync(user, userModel.Password);
                if (result.Succeeded)
                {
                    //inserting to User table todo handle all the fields of the user data like address and others in another form when user updates its profile
                    var client = TMCHttpClient.GetClient();
                    UserViewModel userViewModel = new UserViewModel();
                    userViewModel.UserId = 0;
                    userViewModel.UserName = user.MobileNo;
                    JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto };
                    string serializedItemToCreate = JsonConvert.SerializeObject(userViewModel, settings);

                    var response = await client.PostAsync("api/account", new StringContent(serializedItemToCreate, System.Text.Encoding.Unicode, "application/json"));

                    await SignInAsync(user, false, userModel.Password);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(userModel);
        }