// GET: getData public ActionResult Index() { /* * // using hard coded values to gerenarte drop downlist * SelectListItem slt = new SelectListItem(); * slt.Value = "Germany"; * slt.Text = "Germany"; * slt.Selected = true; //this value will be selctedby default when list populates * * SelectListItem slt1 = new SelectListItem(); * slt1.Value = "Sweden"; * slt1.Text = "Sweden"; * slt1.Selected = false; * * * * sl.Add(slt); * sl.Add(slt1); * * ViewData["item"] = sl; */ //generating countries list from hard coded Model CountryNames cn = new CountryNames(); foreach (var item in cn.getCountryList()) { sl.Add(item); } ViewData["item"] = sl; ViewData["experienceInYears"] = new YearsOfExperience().GetExperience(); return(View()); }
public IHttpActionResult PostYearsOfExperienceViewModel(YearsOfExperienceViewModel yearsOfExperienceViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } YearsOfExperience YearsOfExperience = new YearsOfExperience(); Mapper.CreateMap <YearsOfExperienceViewModel, YearsOfExperience>(); YearsOfExperience = Mapper.Map <YearsOfExperienceViewModel, YearsOfExperience>(yearsOfExperienceViewModel); db.YearsOfExperience.Add(YearsOfExperience); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = yearsOfExperienceViewModel.Id }, yearsOfExperienceViewModel)); }
public IHttpActionResult PutYearsOfExperienceViewModel(int id, YearsOfExperienceViewModel yearsOfExperienceViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != yearsOfExperienceViewModel.Id) { return(BadRequest()); } YearsOfExperience YearsOfExperience = new YearsOfExperience(); Mapper.CreateMap <YearsOfExperienceViewModel, YearsOfExperience>(); YearsOfExperience = Mapper.Map <YearsOfExperienceViewModel, YearsOfExperience>(yearsOfExperienceViewModel); db.Entry(YearsOfExperience).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!YearsOfExperienceExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }