public UserProfileModel GetUserProfile(int inputId)
 {
     UserProfileModel result = new UserProfileModel();
     using (SmartParkingEntities context = new SmartParkingEntities())
     {
         var usr = context.UserProfiles.Where(u => u.UserID == inputId).SingleOrDefault();
         if (usr != null)
         {
             result = ConvertDBToModelObject(usr);
         }
     }
     return result;
 }
        public async Task<ActionResult> AddUser(UserProfileModel userToAdd)
        {
            bool result = false;
            using (var client = new HttpClient())
            {
                string url = System.Configuration.ConfigurationManager.AppSettings["SmartParkingAPI"];
                client.BaseAddress = new Uri(url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response = await client.PostAsJsonAsync("api/UserProfile/PostUserProfile", userToAdd);
                if (response.IsSuccessStatusCode)
                {
                    result = await response.Content.ReadAsAsync<bool>();
                }
            }

            return PartialView("_UsersGrid");
        }
 public async Task<ActionResult> User_Destroy([DataSourceRequest]DataSourceRequest request, UserProfileModel user)
 {
     List<UserProfileModel> users = new List<UserProfileModel>();
     using (var client = new HttpClient())
     {
         string url = System.Configuration.ConfigurationManager.AppSettings["SmartParkingAPI"];
         client.BaseAddress = new Uri(url);
         client.DefaultRequestHeaders.Accept.Clear();
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         user.IsActive = false;
         HttpResponseMessage response = await client.PostAsJsonAsync("api/UserProfile/PostUpdateUserProfile", user);
         if (response.IsSuccessStatusCode)
         {
             users = await response.Content.ReadAsAsync<List<UserProfileModel>>();
         }
     } DataSourceResult result = users.ToDataSourceResult(request);
     return Json(result, JsonRequestBehavior.AllowGet);
 }
        public async Task<ActionResult> GetUserEditForm(int userID)
        {
            UserProfileModel userToEdit = new UserProfileModel();
            using (var client = new HttpClient())
            {
                string url = System.Configuration.ConfigurationManager.AppSettings["SmartParkingAPI"];
                client.BaseAddress = new Uri(url);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response = await client.GetAsync("api/UserProfile/GetUserProfile/" + userID);
                if (response.IsSuccessStatusCode)
                {
                    userToEdit = await response.Content.ReadAsAsync<UserProfileModel>();
                }
            }

            ViewBag.Mode = "Edit";
            return PartialView("_UserForm", userToEdit);
        }
        public bool PostUpdateUserProfile(UserProfileModel usr)
        {
            bool result = false;
            using (SmartParkingEntities context = new SmartParkingEntities())
            {
                UserProfile usrProfile = context.UserProfiles.Where(u => u.UserID == usr.UserID).SingleOrDefault();
                usrProfile.FirstName = usr.FirstName;
                usrProfile.LastName = usr.LastName;
                usrProfile.EmailID = usr.EmailID;
                usrProfile.MobileNumber = usr.MobileNumber;
                usrProfile.Address1 = usr.Address1;
                usrProfile.Address2 = usr.Address2;
                usrProfile.City = usr.City;
                usrProfile.State = usr.State;
                usrProfile.Pincode = usr.Pincode;
                usrProfile.ActiveVehicleNumber = usr.ActiveVehicleNumber;
                usrProfile.IsActive = usr.IsActive;

                context.SaveChanges();

                result = true;
            }
            return result;
        }
        public int PostUserProfile(UserProfileModel usr)
        {
            int result = 0;
            using (SmartParkingEntities context = new SmartParkingEntities())
            {
                UserProfile usrProfile = new UserProfile()
                {
                    FirstName = usr.FirstName,
                    LastName = usr.LastName,
                    EmailID = usr.EmailID,
                    MobileNumber = usr.MobileNumber,
                    Address1 = usr.Address1,
                    Address2 = usr.Address2,
                    City = usr.City,
                    State = usr.State,
                    Pincode = usr.Pincode,
                    ActiveVehicleNumber = usr.ActiveVehicleNumber,
                    IsActive = usr.IsActive
                };

                context.UserProfiles.Add(usrProfile);
                context.SaveChanges();
                result = usrProfile.UserID;
            }
            return result;
        }