public IHttpActionResult Put(LawyerViewModel lawyer) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } using (var ctx = new LawyerDbEntities()) { var existingLawyer = ctx.Lawyers.Where(l => l.Id == lawyer.Id) .FirstOrDefault <Lawyer>(); if (existingLawyer != null) { existingLawyer.Name = lawyer.Name; existingLawyer.Surname = lawyer.Surname; existingLawyer.Initials = lawyer.Initials; existingLawyer.DateOfBirth = lawyer.DateOfBirth; existingLawyer.Email = lawyer.Email; existingLawyer.Gender = lawyer.Gender; existingLawyer.Title = lawyer.Title; ctx.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
public IHttpActionResult GetAllLawyers(int lid) { LawyerViewModel student = null; using (var ctx = new LawyerDbEntities()) { student = ctx.Lawyers.Include("Name") .Where(l => l.Id == lid) .Select(l => new LawyerViewModel() { Id = l.Id, Name = l.Name, Surname = l.Surname, Initials = l.Initials, DateOfBirth = l.DateOfBirth, Email = l.Email, Gender = (short)l.Gender, Title = (short)l.Title }).FirstOrDefault <LawyerViewModel>(); } if (student == null) { return(NotFound()); } return(Ok(student)); }
//Get action methods of the previous section public IHttpActionResult PostNewLawyer(LawyerViewModel lawyer) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } using (var ctx = new LawyerDbEntities()) { ctx.Lawyers.Add(new Lawyer() { Id = lawyer.Id, Name = lawyer.Name, Surname = lawyer.Surname, Initials = lawyer.Initials, DateOfBirth = lawyer.DateOfBirth, Email = lawyer.Email, Gender = lawyer.Gender, Title = lawyer.Title }); ctx.SaveChanges(); } return(Ok()); }
public ActionResult Lawyer_Update([DataSourceRequest] DataSourceRequest request, LawyerViewModel db) { if (db != null && ModelState.IsValid) { LawyerService.Update(db); } return(Json(new[] { db }.ToDataSourceResult(request, ModelState))); }
public ActionResult Edit(LawyerViewModel lawyer) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44372/api/Lawyer"); //HTTP POST var putTask = client.PutAsJsonAsync <LawyerViewModel>("lawyer", lawyer); putTask.Wait(); var result = putTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View(lawyer)); }
public ActionResult Create(LawyerViewModel lawyer) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44372/api/lawyer"); //HTTP POST var postTask = client.PostAsJsonAsync <LawyerViewModel>("lawyer", lawyer); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); return(View(lawyer)); }
public async Task <IActionResult> CreateLawyerAsync(LawyerViewModel model) { if (!ModelState.IsValid) { return(View()); } var newLawyer = new Lawyer() { Name = model.Name, Email = model.Email, PhoneNo = model.PhoneNo, YearsOfExperience = model.YearsOfExperience, TimeStamp = DateTime.Now, Address = model.Address, Expertise = model.Expertise }; await dbContext.Lawyers.AddAsync(newLawyer); await dbContext.SaveChangesAsync(); return(View()); }
public ActionResult Edit(int id) { LawyerViewModel lawyer = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44372/api/"); //HTTP GET var responseTask = client.GetAsync("Lawyer/GetAllLawyersByID?lid=" + id.ToString()); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <LawyerViewModel>(); readTask.Wait(); lawyer = readTask.Result; } } return(View(lawyer)); }
public ActionResult Lawyer_Destroy([DataSourceRequest] DataSourceRequest request, LawyerViewModel db) { if (ModelState.IsValid) { try { if (db != null) { LawyerService.Destroy(db); } } catch (Exception) { ModelState.AddModelError("خطأ", "لا يمكن الحذف"); return(Json(new[] { db }.ToDataSourceResult(request, ModelState))); } } return(Json(new[] { db }.ToDataSourceResult(request, ModelState))); }
public ActionResult Lawyer_Destroy([DataSourceRequest] DataSourceRequest request, LawyerViewModel db) { if (db != null) { LawyerService.Destroy(db); } return(Json(new[] { db }.ToDataSourceResult(request, ModelState))); }