public async Task <bool> AddStudent(VMStudent student) { var std = _mapper.Map <Student>(student); await _studentService.AddAsync(std); return(true); }
public IActionResult GetByName([FromBody] ApiSettings apiSettings) { VMStudent std = ConvertJson.Deserialize <VMStudent>(apiSettings.Obj.ToString()); List <VMStudent> vmStd = _studentService.GetByName(std); return(Json(vmStd)); }
public IActionResult AddStudent(ApiSettings apiSettings) { VMStudent std = ConvertJson.Deserialize <VMStudent>(apiSettings.Obj.ToString()); _studentService.AddStudent(std); return(Ok("Success")); }
public List <VMStudent> GetByName(VMStudent student) { List <Student> stdList = _studentService.GetAll().ToList <Student>(); var vmList = _mapper.Map <List <VMStudent> >(stdList); List <VMStudent> vmStd = vmList.Where(x => x.Name == student.Name && x.Address == student.Address).ToList(); return(vmStd); }
public async Task <IActionResult> Insert() { VMStudent std = new VMStudent() { Name = "MgMg", Address = "Mandalay" }; apiSettings.Action = "add"; apiSettings.Id = 0; apiSettings.Obj = ConvertJson.Serialize(std); await _apiHelper.PostRequest(apiPath, apiSettings); return(View()); }
public IActionResult Student() { VMStudent vm = new VMStudent(); string data = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri(apiPath); var responseTask = client.GetAsync("api/student2/GetById/2"); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsStringAsync(); readTask.Wait(); data = readTask.Result; vm = JsonConvert.DeserializeObject <VMStudent>(data); } } return(View(vm)); }
public ActionResult Index(VMStudent vmStudent) { Student user = Mapper.Map <VMStudent, Student>(vmStudent); user = db.Students.Where(a => a.FirstName == vmStudent.FirstName && a.LastName == vmStudent.LastName).SingleOrDefault(); if (user == null) { user = new Student() { FirstName = vmStudent.FirstName, LastName = vmStudent.LastName, }; db.Students.Add(user); db.SaveChanges(); } Session["User"] = user; return(RedirectToAction("Index", "Posts")); }