Ejemplo n.º 1
0
        public ActionResult Delete(string id)
        {
            var subjectRepository = new SubjectRepository(_context);

            subjectRepository.Delete(new Guid(id));
            _context.Save(_loggedUser);
            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
        public int DeleteSubject(int id)
        {
            SqlObject.CommandText = StoredProcedures.Subjects.DeleteSubject;
            SqlObject.Parameters  = new object[] { id };
            int result = _repository.Delete(id);

            return(result);
        }
Ejemplo n.º 3
0
        public void DeleteSubjectTest()
        {
            SubjectRepository rep = new SubjectRepository();

            rep.Delete(16);
            Subject plan = rep.Read(16);

            Assert.IsNull(plan);
        }
Ejemplo n.º 4
0
        public void DeleteByNullValue()
        {
            // Arrange
            SubjectRepository subjectRepository = new SubjectRepository(dbContext);

            // Act
            // Assert
            Assert.ThrowsException <ArgumentNullException>(() => subjectRepository.Delete(entityToDelete: null));
        }
Ejemplo n.º 5
0
        public void DeleteByNullKey_Exception()
        {
            // Arrange
            SubjectRepository subjectRepository = new SubjectRepository(dbContext);
            object            wrongId           = null;

            // Act
            // Assert
            Assert.ThrowsException <ArgumentNullException>(() => subjectRepository.Delete(wrongId));
        }
Ejemplo n.º 6
0
        public void DeleteByWrongKey_Exception()
        {
            // Arrange
            SubjectRepository subjectRepository = new SubjectRepository(dbContext);
            Guid wrongId = default(Guid);

            // Act
            // Assert
            Assert.ThrowsException <InvalidOperationException>(() => subjectRepository.Delete(wrongId));
        }
        public ActionResult Delete(SubjectViewModel subjectViewModel)
        {
            SubjectRepository repository = new SubjectRepository();

            if (subjectViewModel.Id.ToString() != String.Empty)
            {
                repository.Delete(subjectViewModel.Id);
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Delete(int id)
        {
            var user = await subjectRepository.Get(id);

            if (user == null)
            {
                return(NotFound(new { status = ResultStatus.STATUS_NOT_FOUND, message = "Không tìm thấy môn học" }));
            }
            await subjectRepository.Delete(id);

            return(Ok(new { status = ResultStatus.STATUS_OK, message = "Xóa thành công!" }));
        }
Ejemplo n.º 9
0
 public ActionResult Delete(int id)
 {
     try
     {
         _subjectRepository.Delete(id);
         return(Json(new { result = "success" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception e)
     {
         return(Json(new { result = e.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Ejemplo n.º 10
0
        public IHttpActionResult DeleteSubject(int id)
        {
            var subject = subjectRepo.GetById(id);

            if (subject == null)
            {
                return(Content(HttpStatusCode.NotFound, "Item does not exist"));
            }

            subjectRepo.Delete(id);

            return(Ok());
        }
Ejemplo n.º 11
0
        public void DeleteByValue()
        {
            // Arrange
            SubjectRepository subjectRepository = new SubjectRepository(dbContext);
            Subject           subjectToDelete   = dbContext.Subjects.First(s => s.Name == "Subject 1");

            // Act
            // This subject has messages that must have "subject: null" when one will be deleted.
            subjectRepository.Delete(subjectToDelete);
            dbContext.SaveChanges();

            // Assert
            CollectionAssert.DoesNotContain(dbContext.Subjects.ToArray(), subjectToDelete);
            // Checks if all subject's messages are null.
            Assert.IsTrue(dbContext.Messages.AsEnumerable().Any(m => m.Subject == null || m.Subject.Id != subjectToDelete.Id));
        }
Ejemplo n.º 12
0
        public void DeleteByChangedValue()
        {
            // Arrange
            SubjectRepository subjectRepository      = new SubjectRepository(dbContext);
            Subject           changedSubjectToDelete = dbContext.Subjects.First(s => s.Name == "Subject 1");

            changedSubjectToDelete.Name += "Changed it";

            // Act
            subjectRepository.Delete(entityToDelete: changedSubjectToDelete);
            dbContext.SaveChanges();

            // Assert
            CollectionAssert.DoesNotContain(dbContext.Subjects.ToArray(), changedSubjectToDelete);
            // Checks if all subject's messages are null.
            Assert.IsTrue(dbContext.Messages.AsEnumerable().Any(m => m.Subject == null || m.Subject.Id != changedSubjectToDelete.Id));
        }
        public ActionResult DeleteSubject(SubjectDeleteSubjectVM model)
        {
            SubjectRepository subjectRepo = new SubjectRepository();

            Subject subject = subjectRepo.GetByID(model.SubjectID);

            if (subject.CourseSubject.Count() > 0)
            {

                ModelState.AddModelError("Error", "Subject contains teacher or course");
                model.SubjectID = subject.ID;
                model.SubjectName = subject.Name;
                return View(model);
            }

            subjectRepo.Delete(subject);

            return RedirectToAction("ListSubjects", "Subject");
        }
Ejemplo n.º 14
0
 public void Delete(SubjectDM domain)
 {
     try
     {
         _SubjectRepo.Delete(domain);
     }
     catch (Exception ex)
     {
         //Errors in this scope indicates system error (not validation errors)
         //If error not handled, log it and add system error
         if (!_GlobalErrors.ErrorHandled)
         {
             _Logger.Error(ex, "Database Error: Cannot Delete Subject!");
             _GlobalErrors.AddSystemError("Database Error: Cannot Delete Subject!");
             _GlobalErrors.ErrorHandled = true;
         }
         throw;
     }
 }
Ejemplo n.º 15
0
        public JsonResult DeleteSubject(int id)
        {
            bool subjectInUse = false;
            CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
            List <Course>           courseList = new List <Course>();

            courseList = courseSubjectRepository.GetAll(filter: cs => cs.Subject.Id == id).Select(c => c.Course).ToList();
            if (courseList.Count > 0)
            {
                subjectInUse = true;
            }
            else
            {
                SubjectRepository subjectRepository = new SubjectRepository();
                Subject           subject           = new Subject();
                subject = subjectRepository.GetById(id);
                subjectRepository.Delete(subject);
            }
            return(Json(subjectInUse, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 16
0
        public IHttpActionResult Delete(int tid, int sid)
        {
            List <Subject> subList = techRepo.GetSubjectByTeacher(tid);
            Subject        subject = subRepo.GetById(sid);
            bool           check   = false;

            foreach (var item in subList)
            {
                if (item.SubjectId == subject.SubjectId)
                {
                    check = true;
                }
            }

            if (check == false)
            {
                return(StatusCode(HttpStatusCode.Unauthorized));
            }

            subRepo.Delete(sid);
            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 17
0
        public void testDelete()
        {
            // Arrange
            repo.Add(entity);
            repo.SaveChanges();
            int count = repo.All().Count();

            Guid id = repo.GetByName(n).Id;

            // Act
            repo.Delete(entity);
            repo.SaveChanges();
            // Assert

            Assert.Null(repo.GetByName(n));
            Assert.True(repo.All().Count() == count - 1);
            Assert.True(repo.GetById(id).IsDeleted);

            this.repo.HardDelete(entity);
            this.repo.SaveChanges();

            //TODO add all remaining methods
        }
Ejemplo n.º 18
0
        public void Delete(int id)
        {
            var marks = _markRepository.GetAllBy(i => i.StudentId == id).ToList();

            //var mark = _markRepository.GetFirstValue(markObj.Id);
            foreach (var mark in marks)
            {
                var result = _markRepository.Delete(mark);
            }
            var subjects = _subjectRepository.GetAllBy(i => i.StudentId == id).ToList();

            foreach (var subject in subjects)
            {
                //var subject = _subjectRepository.GetFirstValue(subjectObj.Id);
                _subjectRepository.Delete(subject);
            }
            var students = _studentRepository.GetAllBy(i => i.Id == id).ToList();

            //var student = _studentRepository.GetFirstValue(studentObj.Id);
            foreach (var student in students)
            {
                _studentRepository.Delete(student);
            }
        }
Ejemplo n.º 19
0
        // DELETE api/values/5
        public IHttpActionResult Delete(int id)
        {
            var updatedRowsCount = repo.Delete(id);

            return(new ResponseClass(JsonConvert.SerializeObject(updatedRowsCount), Request));
        }
 public JsonResult DeleteSubject(int id)
 {
     bool subjectInUse = false;
     CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
     List<Course> courseList = new List<Course>();
     courseList = courseSubjectRepository.GetAll(filter: cs => cs.Subject.Id == id).Select(c => c.Course).ToList();
     if (courseList.Count > 0)
     {
         subjectInUse = true;
     }
     else
     {
         SubjectRepository subjectRepository = new SubjectRepository();
         Subject subject = new Subject();
         subject = subjectRepository.GetById(id);
         subjectRepository.Delete(subject);
     }
     return Json(subjectInUse, JsonRequestBehavior.AllowGet);
 }
Ejemplo n.º 21
0
        public async Task <MessageResult> Delete(int SubjectID)
        {
            var repository = new SubjectRepository();

            return(await repository.Delete(SubjectID));
        }
 public void Delete(int id)
 {
     subjectRepository.Delete(id);
 }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            int counter = 1;
            IStudentRepository studentRepository = new StudentRepository();
            ISubjectRepository subjectRepository = new SubjectRepository();

            while (true)
            {
                Console.WriteLine("Enter 1 to add new student\n" +
                                  "Enter 2 to view students list\n" +
                                  "Enter 3 to exit\n" +
                                  "Enter 4 to edit list\n" +
                                  "Enter 5 to add subjects for student\n" +
                                  "Enter 6 to edit subjects\n" +
                                  "Enter 7 to delete subject\n" +
                                  "Enter 8 to view details");
                int switcher = int.Parse(Console.ReadLine());
                switch (switcher)
                {
                case 1:
                    Student student = new Student();
                    student.Id = counter;
                    Console.Write("Enter name: ");
                    student.Name = Console.ReadLine();
                    Console.Write("Enter surname: ");
                    student.Surname = Console.ReadLine();
                    studentRepository.Create(student);
                    counter++;
                    Console.WriteLine($"{student.Name} {student.Surname} has been added");
                    break;

                case 2:
                    if (studentRepository.Count() != 0)
                    {
                        foreach (var st in studentRepository.Get())
                        {
                            Console.Write(st.Id);
                            Console.WriteLine($". {st.Name} {st.Surname} {st.Rating}");
                        }
                    }
                    else
                    {
                        Console.WriteLine("List is empty");
                    }

                    break;

                case 4:
                    Console.Write("Enter ID of a student, who you want to edit: ");
                    int editId = int.Parse(Console.ReadLine());
                    Console.Write("Write new name: ");
                    var name = Console.ReadLine();
                    Console.Write("Write new surname: ");
                    var surname = Console.ReadLine();
                    Console.WriteLine("Student has been successfully edited");
                    studentRepository.Update(editId, name, surname);
                    break;

                case 3:
                    return;

                case 5:
                    Console.WriteLine("Enter ID of a student, whom you want to add subject: ");
                    Subject subject = new Subject();
                    int     addId   = int.Parse(Console.ReadLine());
                    Console.Write("Write name of Subject: ");
                    subject.SubjectName = Console.ReadLine();
                    Console.Write("Write mark of subject: ");
                    subject.Mark = int.Parse(Console.ReadLine());
                    subjectRepository.Create(addId, subject);
                    break;

                case 6:
                    Console.WriteLine("Enter ID of a student, whose subject you want to edit: ");
                    int editSubId = int.Parse(Console.ReadLine());
                    Console.Write("Write name of subject, which you want to edit");
                    string editName = Console.ReadLine();
                    Console.Write("Enter new mark: ");
                    var mark = int.Parse(Console.ReadLine());
                    subjectRepository.Update(editSubId, editName, mark);
                    Console.WriteLine("Subject was successfully edited");
                    break;

                case 7:
                    Console.WriteLine("Enter ID of a student, whose subject you want to delete: ");
                    int deleteId = int.Parse(Console.ReadLine());
                    Console.Write("Write name of subject, which you want to delete");
                    string deleteName = Console.ReadLine();
                    subjectRepository.Delete(deleteId, deleteName);
                    break;

                case 8:
                    Console.WriteLine("Enter ID of a student, who you want to see details: ");
                    int viewId = int.Parse(Console.ReadLine());
                    var st1    = studentRepository.Get(viewId);
                    Console.WriteLine($"ID: {st1.Id}");
                    Console.WriteLine($"Name: {st1.Name}");
                    Console.WriteLine($"Surname: {st1.Surname}");
                    Console.WriteLine($"Rating: {st1.Rating}");
                    Console.WriteLine("Subjects:");
                    foreach (var sub in st1.Subjects)
                    {
                        Console.WriteLine($"\t{sub.SubjectName} {sub.Mark}");
                    }
                    break;

                default:
                    throw new Exception("Wrong numb");
                }
            }
        }
 //[AdminAuthorization]
 public IHttpActionResult Deletesubject([FromUri] int id, [FromUri] int id2)
 {
     subrepo.Delete(id2);
     return(StatusCode(HttpStatusCode.NoContent));
 }