Esempio n. 1
0
        public SubjectCreationResult EditSubjectEssayById(Subject_Essay subject)
        {
            var check = db.Subject_Essay.Where(x => x.id == subject.id).FirstOrDefault();

            if (check == null)
            {
                return(new SubjectCreationResult
                {
                    IsSuccess = false
                });
            }
            else
            {
                var sub = db.Subject_Essay.Where(x => (x.id != subject.id) &&
                                                 (x.subessay_id == subject.subessay_id || x.name == subject.name)).FirstOrDefault();
                if (sub != null)
                {
                    return(new SubjectCreationResult
                    {
                        IsSuccess = false
                    });
                }
                else
                {
                    check.subessay_id = subject.subessay_id;
                    check.name        = subject.name;
                    db.SaveChanges();
                    return(new SubjectCreationResult
                    {
                        IsSuccess = true,
                        Subessay_Id = check.subessay_id,
                        Name = check.name
                    });
                }
            }
            //var sub = db.Subject_Essay.Where(x => x.id == subject.id).FirstOrDefault();
            //if (sub == null)
            //{
            //    return new SubjectCreationResult
            //    {
            //        IsSuccess = false
            //    };
            //}
            //else
            //{
            //    sub.subessay_id = subject.subessay_id;
            //    sub.name = subject.name;
            //    db.SaveChanges();
            //    return new SubjectCreationResult
            //    {
            //        IsSuccess = true,
            //        Subessay_Id = sub.subessay_id,
            //        Name = sub.name
            //    };
            //}
        }
Esempio n. 2
0
        public string DeleteSubjectEssay(Subject_Essay subject)
        {
            var essay = db.Essays.Where(x => x.sub_id == subject.id).ToList();

            foreach (var item in essay)
            {
                db.Essays.Remove(item);
                db.SaveChanges();
            }
            var rate = db.RateStars.Where(x => x.sub_id == subject.id).ToList();

            foreach (var item in rate)
            {
                db.RateStars.Remove(item);
                db.SaveChanges();
            }
            var time = db.Times.Where(x => x.sub_id == subject.id).ToList();

            foreach (var item in time)
            {
                db.Times.Remove(item);
                db.SaveChanges();
            }
            var search = db.SearchFiles.Where(x => x.sub_id == subject.id).ToList();

            foreach (var item in search)
            {
                db.SearchFiles.Remove(item);
                db.SaveChanges();
            }
            var sub = db.Subject_Essay.Where(x => x.id == subject.id).FirstOrDefault();

            db.Subject_Essay.Remove(sub);
            db.SaveChanges();

            return("Xóa thành công");
        }