public ActionResult UpdateStudentInfo(int?Id) // Student Id { try { if (Id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StudentUpdateModel studentUpdateModel = new StudentUpdateModel(); studentUpdateModel.StudentId = (int)Id; using (var context = new JustHallAtumationEntities()) { var student = context.Students.Where(x => x.StudentId == (int)Id).FirstOrDefault(); studentUpdateModel.StudentName = student.StudentName; studentUpdateModel.FatherName = student.FatherName; studentUpdateModel.MotherName = student.MotherName; studentUpdateModel.MobileNumber = student.MobileNumber; studentUpdateModel.room = context.Rooms.ToList(); } return(View(studentUpdateModel)); } catch (Exception ex) { return(View(ex)); } }
public JsonResult StudentUpdate(StudentUpdateModel model) { var usermanager = IdentityTools.NewUserManager(); bool result = false; Student std = SrRepo.Get(x => x.Id == model.StdId); std.Name = model.Name; std.Surname = model.Surname; std.Adress = model.Adress; std.ClassId = model.ClassId; std.IdentificationNo = model.IdentificationNo; ApplicationUser au = usermanager.FindById(std.UserId); au.Email = model.Email; au.UserName = model.Email; if (SrRepo.Update(std)) { var uresult = usermanager.Update(au); if (uresult.Succeeded) { result = true; } } return(Json(result, JsonRequestBehavior.AllowGet)); }
public async Task <Response> Update(StudentUpdateModel studentUpdateModel) { using (var context = _applicationDbContextFactory.Create()) { var Student = Mapper.Map <Student>(studentUpdateModel); if (!context.Students.Any(i => i.Id == Student.Id)) { return new Response { Status = 500, Message = "Нет такого студента!" } } ; if (!context.Check <City>(studentUpdateModel.CityId)) { return new Response { Status = 500, Message = "Такого города нет!" } } ; context.Students.Update(Student); context.SaveChanges(); return(new Response { Status = 100, Message = "Запрос успешно прошел" }); } }
public bool UpdateOne(StudentUpdateModel model, int id) { try { var student = new Student() { FirstName = model.FirstName, SurName = model.SurName, Age = model.Age, ID = id }; Update(student, id); Log.Information("Updated student {0}", model.SurName); return(true); } catch (System.Exception ex) { Log.Error(ex, "Exceptions occurred in student update"); return(false); } }
public ActionResult StudentEdit(StudentUpdateModel model) { if (ModelState.IsValid) { studentInformation.UpdateStudent(model); } return(RedirectToAction("StudentDetails")); }
public async Task <StudentModelBase> Update(StudentUpdateModel model) { var entity = _mapper.Map <Student>(model); _context.Students.Attach(entity); _context.Entry(entity).State = EntityState.Modified; await SaveAsync(); return(_mapper.Map <StudentModelBase>(entity)); }
//To Get data from user public ActionResult StudentEdit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StudentUpdateModel studentUpdateModel = new StudentUpdateModel(); studentUpdateModel.StudentId = (int)id; return(View(studentUpdateModel)); }
public async Task <ActionResult <IStudent> > Put(Guid id, StudentUpdateModel model) { var student = await _studentsRepository.SelectById(id); if (student == null) { return(NotFound()); } if (!string.IsNullOrEmpty(model.Alias)) { var aliases = await _studentsRepository.SelectByAlias(model.Alias); if (aliases.Any()) { ModelState.AddModelError("Alias", "Студент с таким позывным уже существует"); } } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!string.IsNullOrEmpty(model.Fam)) { student.Fam = model.Fam; } if (!string.IsNullOrEmpty(model.Nam)) { student.Nam = model.Nam; } if (!string.IsNullOrEmpty(model.Oth)) { student.Oth = model.Oth; } if (!string.IsNullOrEmpty(model.Alias)) { student.Alias = model.Alias; } if (model.Pol != null) { student.Pol = model.Pol; } student.LastModifyDate = DateTime.Now; await _studentsRepository.Update(student); return(new ObjectResult(student)); }
public IActionResult Update([FromQuery] StudentUpdateModel studentUpdateModel) { Student student = _studentLogic.GetStudentById(studentUpdateModel.Id); if (student == null) { return(NoContent()); } student.Name = studentUpdateModel.Name; student.Age = studentUpdateModel.Age; student.Class = studentUpdateModel.Class; _studentLogic.UpdateStudent(student); return(Ok("Student Info Updated")); }
public IActionResult Update(int studentId, [FromBody] StudentUpdateModel model) { var student = _mapper.Map <Student>(model); try { _studentService.Update(student, studentId); return(Ok()); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
// Student data update from UpdateController public bool UpdateStudent(StudentUpdateModel model) { using (var context = new HallAutomationSystemEntities()) { var student = context.Student.FirstOrDefault(x => x.StudentId == model.StudentId); RoomInformation roomInformation = new RoomInformation(); roomInformation.UpdateRoom((int)student.RoomId, 1); if (student != null) { student.StudentName = model.StudentName; student.FatherName = model.FatherName; student.MotherName = model.MotherName; student.MobileNumber = model.MobileNumber; student.RoomId = (int)GetRoomId(model.RoomNumber); } roomInformation.UpdateRoom((int)student.RoomId, -1); context.SaveChanges(); return(true); } }
public IActionResult Put([FromBody] StudentUpdateModel student) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = unitOfWork.Student.UpdateOne(student, student.ID); return(Ok(new { result })); } catch (Exception ex) { Log.Error(ex, "Exceptions occurred in put student api"); return(StatusCode(500, ex.Message)); } }
// For updating StudnetInformation public int StudentInformationUpdate(StudentUpdateModel model) { using (var context = new JustHallAtumationEntities()) { var student = context.Students.Where(x => x.StudentId == model.StudentId).FirstOrDefault(); if (student != null) { student.StudentName = model.StudentName; student.RoomId = model.RoomId; student.FatherName = model.FatherName; student.MotherName = model.MotherName; student.MobileNumber = model.MobileNumber; student.PaymentId = null; } else { return(-1); } context.SaveChanges(); return(student.StudentId); } }
public ActionResult UpdateStudentInfo(StudentUpdateModel model) { try { if (ModelState.IsValid) { int id = updateOperation.StudentInformationUpdate(model); if (id > 0) { ModelState.Clear(); ViewBag.Successs = "Data Updated!"; } else { ViewBag.Success = "Failed!"; } } return(RedirectToAction("Studentslist", "ShowDetails")); } catch (Exception ex) { return(View(ex)); } }
// To show the all details of Student for User public ActionResult StudentDetails() { string UserName = (string)Session["UserName"]; if (UserName == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Users user = searchOperation.GetUser(UserName); Student student = searchOperation.GetStudent(user.UserId); Room room = searchOperation.GetRoom((int)student.RoomId); DepartmentInfo departmentInfo = searchOperation.GetDepartmentInfo(student.StudentId); StudentUpdateModel studentUpdateModel = new StudentUpdateModel(); studentUpdateModel.StudentId = departmentInfo.StudentId; studentUpdateModel.StudentName = student.StudentName; studentUpdateModel.FatherName = student.FatherName; studentUpdateModel.MotherName = student.MotherName; studentUpdateModel.MobileNumber = student.MobileNumber; studentUpdateModel.RoomNumber = (int)room.RoomNumber; return(View(studentUpdateModel)); }
public JsonResult GetStudenyByTc(string TC) { var usermanager = IdentityTools.NewUserManager(); Student model = SrRepo.Get(x => x.IdentificationNo == TC && x.IsDeleted == false); ApplicationUser au = usermanager.FindById(model.UserId); StudentUpdateModel sum = new StudentUpdateModel(); sum.StdId = model.Id; sum.Name = model.Name; sum.Surname = model.Surname; sum.Email = au.Email; sum.Adress = model.Adress; sum.IdentificationNo = model.IdentificationNo; sum.PictureUpload = au.Picture; sum.ClassId = model.ClassId; string value = string.Empty; value = JsonConvert.SerializeObject(sum, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); return(Json(value, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> Update(StudentUpdateModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var dto = _mapper.Map <StudentDto>(model); await _studentService.UpdateStudent(dto); return(Ok()); } catch (EntityNotFoundException) { return(BadRequest("Student with such id does not exist.")); } catch (IncorrectIdException e) { _logger.LogWarning(e, "It seems, validation does not cover some errors."); return(BadRequest(e.Message)); } }
public async Task <ActionResult <Response> > Update(StudentUpdateModel model) { return(await _studentService.Update(model)); }