public bool Update(Department department, bool childIncluded = false)
        {
            var orignal = db.Departments.Include(x => x.Subjects).First(x => x.DepartmentId == department.DepartmentId);

            orignal.DepartmentName = department.DepartmentName;
            if (department.Subjects != null && department.Subjects.Count > 0)
            {
                var subjects = department.Subjects.ToArray();
                for (var i = 0; i < subjects.Length; i++)
                {
                    var temp = orignal.Subjects.FirstOrDefault(c => c.SubjectId == subjects[i].SubjectId);
                    if (temp != null)
                    {
                        temp.SubjectName = subjects[i].SubjectName;
                        temp.Duration    = subjects[i].Duration;
                    }
                    else
                    {
                        orignal.Subjects.Add(subjects[i]);
                    }
                }
                foreach (var c in orignal.Subjects)
                {
                    var temp = department.Subjects.FirstOrDefault(t => t.SubjectId == c.SubjectId);
                    if (temp == null)
                    {
                        db.Entry(c).State = EntityState.Deleted;
                    }
                }
            }

            return(db.SaveChanges() > 0);
        }
Exemplo n.º 2
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 }));
        }
        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));
        }
        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));
        }
Exemplo n.º 5
0
 public ActionResult Edit(Subject subject)
 {
     if (ModelState.IsValid)
     {
         _subjectDbContext.Entry(subject).State = EntityState.Modified;
         _subjectDbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(subject));
 }
 public bool Update(Student s)
 {
     db.Entry(s).State = EntityState.Modified;
     return(db.SaveChanges() > 0);
 }
Exemplo n.º 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));
        }