コード例 #1
0
        public IHttpActionResult PutTeacher(int id, Teacher teacher)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != teacher.TeacherId)
            {
                return(BadRequest());
            }

            db.Entry(teacher).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TeacherExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public IHttpActionResult PutStudent(int id, Student student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != student.StudentId)
            {
                return(BadRequest());
            }

            db.Entry(student).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public ActionResult Create(Subject subject)
        {
            if (ModelState.IsValid)
            {
                _subjectDbContext.dbSet.Add(subject);
                _subjectDbContext.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(subject));
        }
コード例 #4
0
        public ActionResult CheckinAndFinish(int id = 0)
        {
            Subject subject = db.SubjectDatabase.Find(id);

            if (subject != null)
            {
                subject.LastSeen        = DateTime.Now;
                db.Entry(subject).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(RedirectToAction("Index", "Home", new { thanks = 2 }));
        }
コード例 #5
0
 public bool Insert(Student s)
 {
     db.Students.Add(s);
     return(db.SaveChanges() > 0);
 }
コード例 #6
0
 public bool Insert(Subject s)
 {
     db.Subjects.Add(s);
     return(db.SaveChanges() > 0);
 }
コード例 #7
0
        public IHttpActionResult PutDepartment(int id, Department department)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != department.DepartmentId)
            {
                return(BadRequest());
            }

            var ext = db.Departments.Include(x => x.Students).Include(y => y.Teachers).First(x => x.DepartmentId == department.DepartmentId);

            ext.DepartmentName = department.DepartmentName;
            //ext.Address = company.Address;
            //ext.Eshtablished = company.Eshtablished;
            //ext.ContactEmail = company.ContactEmail;
            //ext.Web = company.Web;
            if (department.Students != null && department.Students.Count > 0)
            {
                var prs = department.Students.ToArray();
                for (var i = 0; i < prs.Length; i++)
                {
                    var temp = ext.Students.FirstOrDefault(c => c.StudentId == prs[i].StudentId);
                    if (temp != null)
                    {
                        temp.StudentName = prs[i].StudentName;
                        temp.Birthday    = prs[i].Birthday;
                        temp.Email       = prs[i].Email;
                        temp.Address     = prs[i].Address;
                    }
                    else
                    {
                        ext.Students.Add(prs[i]);
                    }
                }
                prs = ext.Students.ToArray();
                for (var i = 0; i < prs.Length; i++)
                {
                    var temp = department.Students.FirstOrDefault(x => x.StudentId == prs[i].StudentId);
                    if (temp == null)
                    {
                        db.Entry(prs[i]).State = EntityState.Deleted;
                    }
                }
            }
            if (department.Teachers != null && department.Teachers.Count > 0)
            {
                var srvs = department.Teachers.ToArray();
                for (var i = 0; i < srvs.Length; i++)
                {
                    var temp = ext.Teachers.FirstOrDefault(c => c.TeacherId == srvs[i].TeacherId);
                    if (temp != null)
                    {
                        temp.TeacherName = srvs[i].TeacherName;
                        temp.Designation = srvs[i].Designation;
                    }
                    else
                    {
                        ext.Teachers.Add(srvs[i]);
                    }
                }
                srvs = ext.Teachers.ToArray();
                for (var i = 0; i < srvs.Length; i++)
                {
                    var temp = department.Teachers.FirstOrDefault(x => x.TeacherId == srvs[i].TeacherId);
                    if (temp == null)
                    {
                        db.Entry(srvs[i]).State = EntityState.Deleted;
                    }
                }
            }

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DepartmentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #8
0
 public bool Insert(Department department)
 {
     db.Departments.Add(department);
     return(db.SaveChanges() > 0);
 }