public ActionResult AddOrEditAttendance(Attendance attendance) { using (LMSContext db = new LMSContext()) { if (attendance.ID == 0) { var newAtendance = new Attendance(); newAtendance.Date = DateTime.Now; newAtendance.Remark = "test"; var student = db.Students.ToList().FirstOrDefault(); newAtendance.Student = student; db.Attendances.Add(newAtendance); db.SaveChanges(); return(Json(new { success = true, message = "Записът е успешен." }, JsonRequestBehavior.AllowGet)); } else { db.Entry(attendance).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Редакцията е успешна." }, JsonRequestBehavior.AllowGet)); } } }
public IActionResult CreateCourse(Course course) { if (ModelState.IsValid) { context.Courses.Add(course); context.SaveChanges(); return(RedirectToAction("CourseView", new { courseId = course.CourseId })); } return(View()); }
public int AddUser(User user, short roleId) { //if (user.UserId > 0) //{ // UpdateUser(user); //} //var newuser = _db.Users.Add(user); //_db.UserRoles.Add(new UserRole { UserId = newuser.UserId, RoleId = roleId }); return(_db.SaveChanges()); }
public HttpStatusCodeResult Create(UserViewModel user) { if (db.Users.Any(u => u.UserName == user.uname)) { return(new HttpStatusCodeResult(417, "Användarnamnet finns redan, välj ett nytt")); } if (user.password1 != user.password2) { return(new HttpStatusCodeResult(417, "Lösenorden matchar inte")); } if (!ModelState.IsValid) { return(new HttpStatusCodeResult(417, "Du glömde fylla i obligatoriska fält markerade med *")); } var userEnt = new User { FirstName = user.fname, LastName = user.lname, Email = user.email, UserName = user.uname }; var res = UserManager.Create(userEnt, user.password1); if (!res.Succeeded) { throw new Exception(res.Errors.Aggregate("", (a, b) => a + b + "\n")); } UserManager.AddToRole(userEnt.Id, user.role_name); switch (user.role_name) { case "teacher": db.Teachers.Add(new Teacher { User_Id = userEnt.Id }); break; case "student": db.Students.Add(new Student { User_Id = userEnt.Id }); break; default: break; } db.SaveChanges(); var message = string.Format("En {0} med användarnamn: {1} skapades", user.role_name, userEnt.UserName); return(new HttpStatusCodeResult(200, message)); }
public HttpStatusCodeResult Create(string name, string description) { var subject = new Subject { Name = name, Description = description }; db.Subjects.Add(subject); db.SaveChanges(); return(new HttpStatusCodeResult(200, "Ett nytt ämne med id: " + subject.Id.ToString() + "skapades")); }
public int DeleteAsync(int id) { var model = _context.Members.Find(id); var User = _context.Users.Include("Roles").FirstOrDefault(u => u.Id == model.UserId); _context.Members.Remove(model); _context.SaveChanges(); _context.Users.Remove(User); _context.SaveChanges(); return(id); }
public int DeleteAsync(int id) { var model = _context.ReturnBooks.FirstOrDefault(i => i.Id == id); var data = _context.LatePayments.FirstOrDefault(a => a.ReturnBookId == id); if (data != null) { _context.LatePayments.Remove(data); _context.SaveChanges(); } _context.ReturnBooks.Remove(model); _context.SaveChanges(); return(id); }
public int DeleteAsync(int id) { var model = _context.LatePayments.Find(id); _context.LatePayments.Remove(model); _context.SaveChanges(); return(id); }
public int DeleteAsync(int id) { var model = _context.ReserveBooks.Find(id); _context.ReserveBooks.Remove(model); _context.SaveChanges(); return(id); }
public ActionResult AddOrEditSubjectGrade(SubjectGrade subgr) { using (LMSContext db = new LMSContext()) { if (subgr.ID == 0) { db.SubjectGrades.Add(subgr); db.SaveChanges(); return(Json(new { success = true, message = "Записът е успешен." }, JsonRequestBehavior.AllowGet)); } else { db.Entry(subgr).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Редакцията е успешна." }, JsonRequestBehavior.AllowGet)); } } }
public HttpStatusCodeResult Create(string name, int teacherId) { var group = new Group { Name = name, Teacher_Id = teacherId }; db.Groups.Add(group); db.SaveChanges(); //string[] dirs = { "shared", "private" }; //var fileRoot = Server.MapPath("~/Files"); //foreach (var d in dirs) //{ // var path = Path.Combine(fileRoot, group.Name, d); // Directory.CreateDirectory(path); //} return(new HttpStatusCodeResult(200, String.Format("{0}:{1}", group.Id, group.Name))); }
public ActionResult DeleteSubjectGrade(int id) { using (LMSContext db = new LMSContext()) { SubjectGrade subgr = db.SubjectGrades.Where(x => x.ID == id).FirstOrDefault <SubjectGrade>(); db.SubjectGrades.Remove(subgr); db.SaveChanges(); return(Json(new { success = true, message = "Записът е изтрит." }, JsonRequestBehavior.AllowGet)); } }
public ActionResult DeleteAttendance(int id) { using (LMSContext db = new LMSContext()) { Attendance attendance = db.Attendances.Where(x => x.ID == id).FirstOrDefault <Attendance>(); db.Attendances.Remove(attendance); db.SaveChanges(); return(Json(new { success = true, message = "Записът е изтрит." }, JsonRequestBehavior.AllowGet)); } }
public ActionResult DeleteGradeParallel(int id) { using (LMSContext db = new LMSContext()) { GradeParallel grd = db.GradeParallels.Where(x => x.ID == id).FirstOrDefault <GradeParallel>(); db.GradeParallels.Remove(grd); db.SaveChanges(); return(Json(new { success = true, message = "Записът е изтрит." }, JsonRequestBehavior.AllowGet)); } }
public HttpStatusCodeResult Grade(GradingViewModel form) { var teacher = db.Teachers.Find(HttpContext.User.Identity.GetUserId <int>()); var grading = db.Gradings.Add(new Grading { Grade = form.grade, Date = DateTime.Now, Feedback = form.feedback, Teacher_Id = teacher.Id }); db.SaveChanges(); var sub = db.Submissions.Find(form.sub_id); var name = sub.Student.User.FullName; sub.Grading_Id = grading.Id; db.SaveChanges(); var msg = String.Format("Satte betyget ({0}) på '{1}'s inlämning", form.grade, name); return(new HttpStatusCodeResult(200, msg)); }
public HttpStatusCodeResult Create(HttpPostedFileBase file) { var model = new JavaScriptSerializer() .Deserialize(HttpContext.Request.Form["model"], typeof(SubmissionViewModel)) as SubmissionViewModel; var userId = HttpContext.User.Identity.GetUserId <int>(); var student = db.Students.Where(s => s.User_Id == userId).SingleOrDefault(); var sub = db.Submissions.Add(new Submission { SubmitDate = DateTime.Now, Comment = model.comment, Student_Id = student.Id, Assignment_Id = model.aid, }); db.SaveChanges(); string filePath = Server.MapPath("~/Files/Submissions"); Directory.CreateDirectory(filePath); filePath = Path.Combine(filePath, sub.Id + "_" + file.FileName); file.SaveAs(filePath); var upload = new Upload { FilePath = filePath, User_Id = userId }; db.Uploads.Add(upload); db.SaveChanges(); sub.Upload_Id = upload.Id; db.SaveChanges(); var msg = "Laddade upp filen: " + file.FileName; return(new HttpStatusCodeResult(200, msg)); }
public HttpStatusCodeResult Create(ScheduleViewModel model) { var sched = new Schedule { Type = model.type_id, Group_Id = model.group_id, DateStart = model.date_start, DateEnd = model.date_end, Description = model.description }; db.Schedules.Add(sched); sched.Subjects.Add(db.Subjects.Find(model.subject_id)); db.SaveChanges(); var msg = String.Format("En ny händelse ({0}) med id: {1} har skapats", sched.Type.ToString(), sched.Id); return(new HttpStatusCodeResult(200, msg)); }
public void UpdateUserData(string userId, int userProfileId, bool isEmailConfirmed, bool isActive, bool isBlocked) { using (LMSContext entity = new LMSContext()) { var existingUser = entity.AspNetUsers.FirstOrDefault(w => w.Id == userId); if (existingUser != null) { existingUser.EmailConfirmed = isEmailConfirmed; } entity.SaveChanges(); } var existingUserProfile = this._userProfileRepository.Table.FirstOrDefault(w => w.Id == userProfileId); if (existingUserProfile != null) { existingUserProfile.IsActive = isActive; existingUserProfile.IsBlocked = isBlocked; this._userProfileRepository.Update(existingUserProfile); } }
public bool Add(Company company) { _db.Companies.Add(company); return(_db.SaveChanges() > 0 ? true : false); }
public IActionResult Create(Book book) { _dbContext.Book.Add(book); _dbContext.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Create(Student student) { _dbcontext.Student.Add(student); _dbcontext.SaveChanges(); return(RedirectToAction(nameof(Index))); }
public int Save() { return(context.SaveChanges()); }
public IActionResult Create(Borrow borrow) { _dbcontext.Borrow.Add(borrow); _dbcontext.SaveChanges(); return(RedirectToAction("Index")); }