Пример #1
0
        //public List<CountriesDto> CountryStateList(string CountryOrState)
        //{
        //    string filePath = Server.MapPath("/Content/CountryStateList/countries.json");
        //    if (CountryOrState == "states")
        //    {
        //        filePath = Server.MapPath("/Content/CountryStateList/states.json");
        //    }
        //    string jsonData = System.IO.File.ReadAllText(filePath);
        //    StreamReader file = System.IO.File.OpenText(filePath);
        //    var countrylist = JsonConvert.DeserializeObject<List<CountriesDto>>(jsonData);
        //    return countrylist;
        //}


        public JsonResult GetStateById(int CountryId)
        {
            HomeService homeService = new HomeService();
            var         GetState    = homeService.CountryStateList("states");
            var         States      = GetState.Where(x => x.country_id == CountryId).ToList();

            return(Json(new { state = States }, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public ActionResult UserProfile(int?id)
        {
            UserEntities     db          = new UserEntities();
            ProfileViewModel model       = new ProfileViewModel();
            HomeService      homeService = new HomeService();
            //HomeViewModel
            var city = db.tbl_city.ToList();
            var a    = homeService.optionListState();

            model.Cities = db.tbl_city.Select(x => new citymodel
            {
                cityid   = x.Cityid,
                cityname = x.Cityname
            }).ToList();
            model.Countries       = homeService.CountryStateList("Country");
            model.SelectedCountry = 233;
            var states = homeService.CountryStateList("states");

            model.States = states.Where(x => x.country_id == 233).ToList();
            //model.States = CountryStateList("states").Select(x => new SelectListItem
            //{
            //    Text = x.name,
            //    Value = x.id.ToString()
            //}).ToList();
            //model.SelectedState = model.States.Where(x => x.country_id == 233).Select(x => x.id).FirstOrDefault();
            //    //.Select(x => new int {


            //    //   });//; 1456;

            if (id > 0)
            {
                var userlist       = homeService.AddOrEdit(id);
                var seletedcityIds = db.tbl_user.Where(x => x.Userid == id).Select(x => x.CityIds).FirstOrDefault();
                userlist.Cityids = seletedcityIds.Split(',').ToArray();
                //new SelectList(city, "Cityid", "Cityname");
                userlist.Countries = model.Countries;
                userlist.States    = userlist.SelectedCountry != null?states.Where(x => x.country_id == userlist.SelectedCountry).ToList() : new List <CountriesDto>();

                userlist.Cities = model.Cities;
                return(View(userlist));
            }

            return(View(model));
        }
Пример #3
0
        public ActionResult UserProfile(ProfileViewModel model)
        {
            UserEntities db          = new UserEntities();
            HomeService  homeService = new HomeService();

            if (ModelState.IsValid)
            {
                if (model.Userid > 0)
                {
                    var userlist = db.tbl_user.Where(x => x.Userid == model.Userid).FirstOrDefault();
                    userlist.Userid    = model.Userid;
                    userlist.Username  = model.Username;
                    userlist.Email     = model.Email;
                    userlist.Password  = model.Password;
                    userlist.CityIds   = string.Join(",", model.Cityids); //this is for multi select dropdown
                    userlist.cityid    = model.Cityid;                    //this is for simple dropdown
                    userlist.Gender    = model.Gender;
                    userlist.Startdate = Convert.ToDateTime(model.StartDate);
                    userlist.Enddate   = Convert.ToDateTime(model.EndDate);
                    userlist.IsCsharp  = model.IsCsharp == null ? false : model.IsCsharp;
                    userlist.IsJava    = model.IsJava == null ? false : model.IsJava;
                    userlist.IsPaython = model.IsPaython == null ? false : model.IsPaython;
                    userlist.CountryID = model.SelectedCountry;
                    userlist.StateId   = model.SelectedState;
                    if (model.UserImageFile != null)
                    {
                        string filename  = Path.GetFileNameWithoutExtension(model.UserImageFile.FileName);
                        string extension = Path.GetExtension(model.UserImageFile.FileName);
                        filename           = filename + DateTime.Now.ToString("yymmssff") + extension;
                        userlist.ImagePath = "~/Image/" + filename;
                        filename           = Path.Combine(Server.MapPath("~/Image/"), filename);
                        model.UserImageFile.SaveAs(filename);
                    }
                    db.Entry(userlist).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    var user = new tbl_user();
                    if (model.UserImageFile != null)
                    {
                        string filename  = Path.GetFileNameWithoutExtension(model.UserImageFile.FileName);
                        string extension = Path.GetExtension(model.UserImageFile.FileName);
                        filename       = filename + DateTime.Now.ToString("yymmssff") + extension;
                        user.ImagePath = "~/Image/" + filename;
                        filename       = Path.Combine(Server.MapPath("~/Image/"), filename);
                        model.UserImageFile.SaveAs(filename);
                    }

                    user.Username  = model.Username;
                    user.Email     = model.Email;
                    user.Password  = model.Password;
                    user.cityid    = model.Cityid;//this is for simple dropdown
                    user.Gender    = model.Gender;
                    user.Startdate = Convert.ToDateTime(model.StartDate);
                    user.Enddate   = Convert.ToDateTime(model.EndDate);
                    user.IsCsharp  = model.IsCsharp == null ? false : model.IsCsharp;
                    user.IsJava    = model.IsJava == null ? false : model.IsJava;
                    user.IsPaython = model.IsPaython == null ? false : model.IsPaython;
                    user.CityIds   = model.Cityids == null ? string.Empty : string.Join(",", model.Cityids);
                    user.CountryID = model.SelectedCountry;
                    user.StateId   = model.SelectedState;

                    db.tbl_user.Add(user);
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            //var city = db.tbl_city.ToList();
            model.Cities = db.tbl_city.Select(x => new citymodel
            {
                cityid   = x.Cityid,
                cityname = x.Cityname
            }).ToList();
            model.Countries       = homeService.CountryStateList("Country");
            model.SelectedCountry = 233;
            model.States          = homeService.CountryStateList("states");
            model.SelectedState   = 1456;// new SelectList(city, "Cityid", "Cityname");
            return(View(model));
        }