public async Task <IActionResult> AddDepartment([Bind("DepartmentId,DepartmentName,DepartmentCode")] Department department) { if (ModelState.IsValid) { if (department.DepartmentId == 0) { if (DepartmentExist(department.DepartmentCode)) { ViewData["Message"] = "Department code is already exist."; return(View(department)); } else { _context.Departments.Add(department); } } else { _context.Update(department); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } List <Department> departments = await _context.Departments.ToListAsync(); ViewData["Deparments"] = departments; return(View()); }
public async Task <IActionResult> PutStudent([FromRoute] int id, [FromBody] Student student) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != student.Stu_id) { return(BadRequest()); } _context.Entry(student).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult> Create([Bind(Include = "FeesId,Class_Id,FrequencyCategoryId,InvFrequencyId,Academic_Year,FeesDescription,Fees,Created_By,Created_On,Updated_On,Updated_By,Is_Active,Is_Deleted")] Fees_Configuration fees_Configuration, FormCollection formValues) { var userId = LoggedInUser.Id; if (ModelState.IsValid) { string[] ListClass = formValues["Class_Id"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] ListPeriod = formValues["FrequencyCategoryId"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var ClassId in ListClass) { foreach (var FreqId in ListPeriod) { fees_Configuration.Class_Id = Convert.ToInt32(ClassId); fees_Configuration.FrequencyCategoryId = Convert.ToInt32(FreqId); fees_Configuration.Created_By = userId; fees_Configuration.Created_On = DateTime.Now; db.Fees_Config.Add(fees_Configuration); await db.SaveChangesAsync(); } } return(RedirectToAction("Create")); } ViewBag.Class_Id = new SelectList(db.Classes, "Class_Id", "Class_Name", fees_Configuration.Class_Id); ViewBag.FrequencyCategoryId = new SelectList(db.InvFrequencyCategories, "FrequencyCategoryId", "FrequencyCategoryCode", fees_Configuration.FrequencyCategoryId); ViewBag.InvFrequencyId = new SelectList(db.InvoiceFrequencies, "InvFrequencyId", "InvFrequencyValue", fees_Configuration.InvFrequencyId); return(View(fees_Configuration)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Numele,Sectia,An")] Student student) { if (id != student.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(student); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(student.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(student)); }
public async Task <Student> InsertStudentAsync(Student student) { _context.Students.Add(student); await _context.SaveChangesAsync(); return(student); }
public async Task <IActionResult> PutAddress(int id, Address address) { if (id != address.addressId) { return(BadRequest()); } _context.Entry(address).State = EntityState.Modified; if (_context.Find <Student>(address.studentId) == null) { return(BadRequest()); } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AddressExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutStudents(int id, Students students) { if (id != students.Id) { return(BadRequest()); } _context.Entry(students).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IHttpActionResult> PutStudent(string id, Student student) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != student.Id) { return(BadRequest()); } db.Entry(student).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <StudentModel> Add(StudentModel student) { await _context.Student.AddAsync(student); await _context.SaveChangesAsync(); return(student); }
/// <inheritdoc /> public async Task AddStudent(Group group, Student student) { var sg = new StudentGroup { Group = group, Student = student }; await _dbContext.StudentGroups.AddAsync(sg); await _dbContext.SaveChangesAsync(); }
public async Task <IActionResult> Order(int id, ProductOrderViewModel model) { var product = await _context.Products.FindAsync(id); product.Stock = product.Stock - model.Quantity; _context.Products.Update(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("Id,UserName,Password")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Create([Bind("Id,CourseName")] Course course) { if (ModelState.IsValid) { _context.Add(course); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(course)); }
public async Task <IActionResult> Create([Bind("Id,StudentID,Name,Period,InClass,TimeLastCheckedIn,TimeLastCheckedOut,AttendaceStatus")] Student student) { if (ModelState.IsValid) { StudentDatabaseContext.Add(student); await StudentDatabaseContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(student)); }
public async Task <IActionResult> Create([Bind("Id,Name,Age,Course,Email,Contact")] Students students) { if (ModelState.IsValid) { _context.Add(students); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(students)); }
public async Task UpdateStudentAsync(StudentDetailModel student) { var entity = await studentDbContext.Students.FirstOrDefaultAsync(s => s.Id == student.Id); entity.FirstName = student.FirstName; entity.LastName = student.LastName; entity.About = student.About; entity.EnrollmentDate = student.EnrollmentDate; await studentDbContext.SaveChangesAsync(); }
public async Task <IActionResult> Create([Bind("StudentId,Name,Address,Email,MatriNo")] Student student) { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(student)); }
public async Task <IActionResult> Create([Bind("StudentId,FirstName,LastName,City,State")] Student student) { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(student)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Age,Address,CourseId")] Student student) { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CourseId"] = new SelectList(_context.Courses, "Id", "Id", student.CourseId); return(View(student)); }
public async Task <ActionResult> Create([Bind(Include = "Id,Name")] StudyYear studyYear) { if (ModelState.IsValid) { db.StudyYears.Add(studyYear); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(studyYear)); }
public async Task <ActionResult> Create([Bind(Include = "StudentDetail_Id,Student_Id,Identification_Mark1,Identification_Mark2,Is_Allergic,Allergy_Details,Father_Occupation_Id,Father_Annual_Income,Mother_Occupation_Id,Mother_Annual_Income,Caste,Religion,Languages_Known,Second_Language_Opted_Id,Birth_Certificate,Upload_Document1,UpLoad_Document2,Academic_Year,Is_Active,Is_Deleted,Created_On,Created_By,Deleted_On,Deleted_By")] Student_Other_Details student_Other_Details) { if (ModelState.IsValid) { db.Student_Other_Details.Add(student_Other_Details); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(student_Other_Details)); }
public async Task <ActionResult> Create([Bind(Include = "Id,Name")] CurrentTerm currentTerm) { if (ModelState.IsValid) { db.CurrentTerms.Add(currentTerm); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(currentTerm)); }
public async Task<ActionResult<Student>> CreateAsync([Bind("FirstName,LastName,Program")] StudentBase studentBase) { Student student = new Student { FirstName = studentBase.FirstName, LastName = studentBase.LastName, Program = studentBase.Program }; _context.Add(student); await _context.SaveChangesAsync(); return CreatedAtAction(nameof(GetById), new { id = student.ID }, student); }
public async Task <int> AddPost(Post post) { if (db != null) { await db.Post.AddAsync(post); await db.SaveChangesAsync(); return(post.PostId); } return(0); }
public async Task <bool> Add(T entity) { try { context.Set <T>().Add(entity); await context.SaveChangesAsync(); return(await Task.FromResult(true)); } catch { return(await Task.FromResult(false)); } }
public async Task <bool> AddAsync(Student student) { try { _context.Add(student); var newStudent = await _context.SaveChangesAsync(); return(newStudent == 1); } catch (Exception) { return(false); } }
public async Task <Student> CreateAsync(Student enity) { try { var res = await _ctx.AddAsync(enity); await _ctx.SaveChangesAsync(); return(res.Entity); } catch (Exception ex) { throw ex; } }
public async Task <ActionResult <Student> > Create([FromBody] StudentBase student) { var newly = new Student() { FirstName = student.FirstName, LastName = student.LastName, Program = student.Program }; _context.Students.Add(newly); await _context.SaveChangesAsync(); Response.StatusCode = StatusCodes.Status201Created; return(Ok(newly)); }
public async Task <IActionResult> PostCreate([FromBody] StudentRequestModel request) { if (request != null) { var student = new Student { UserName = request.UserName, Password = request.Password, ContactNo = request.ContactNo }; context.Add(student); await context.SaveChangesAsync(); var response = new Response { Status = true, Message = "Student record created successfully", Data = new List <StudentRequestModel> { new StudentRequestModel { UserName = request.UserName, Password = request.Password, ContactNo = request.ContactNo } } }; return(Ok(response)); } return(BadRequest()); }
public async Task <ActionResult <QuotesDTO> > PostQuotes([FromBody] QuotesDTO quotesDTO) { var user = await _userManager.FindByNameAsync(User.Identity.Name); Quotes newQuote = new() { Content = quotesDTO.Content, Author = quotesDTO.Author, UserId = user.Id, }; _context.QuoteSet.Add(newQuote); await _context.SaveChangesAsync(); return(CreatedAtAction("GetQuotes", new { id = newQuote.QuoteId }, newQuote)); }