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

            if (id != tour.Id)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public IHttpActionResult PutProduct(Guid id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.Id)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
 public ActionResult KitapEkle(Kitap kitap)
 {
     if (ModelState.IsValid)
     {
         db.Kitaps.Add(kitap);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
コード例 #4
0
        public IActionResult UpdateProduct(Product product)
        {
            var item = _context.Products.Find(product.id);

            item.name  = product.name;
            item.price = product.price;
            _context.Products.Update(item);
            _context.SaveChanges();
            TempData["nontification"] = "Update success!";
            return(new RedirectResult("GetList"));
        }
コード例 #5
0
        public ActionResult Create([Bind(Include = "Id,Name,Description,Length,Price,Rating,IncludesMeals")] Tour tour)
        {
            if (ModelState.IsValid)
            {
                db.Tours.Add(tour);
                db.SaveChanges();

                return(RedirectToAction("Index", new { notifyUsers = true }));
            }

            return(View(tour));
        }
コード例 #6
0
        public ActionResult Create(product prod, HttpPostedFileBase img)
        {
            string path;

            if (ModelState.IsValid)
            {
                path = Path.Combine(Server.MapPath("~/Content/Uploads/Products"), Path.GetFileName(img.FileName));
                img.SaveAs(path);
                path            = "~/Content/Uploads/Products/" + Path.GetFileName(img.FileName);
                prod.prod_image = path;
                context.products.Add(prod);
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(prod));
        }
コード例 #7
0
        public ActionResult Edit(customer cust)
        {
            var oldCust = context.customers.Find(cust.cust_id);

            try
            {
                oldCust.cust_name  = cust.cust_name;
                oldCust.cus_email  = cust.cus_email;
                oldCust.cust_phone = cust.cust_phone;
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(cust));
            }
        }
コード例 #8
0
        public ActionResult Create(category cat, HttpPostedFileBase img)
        {
            string path;

            if (ModelState.IsValid)
            {
                path = Path.Combine(Server.MapPath("~/Content/Uploads/Category"), Path.GetFileName(img.FileName));
                img.SaveAs(path);
                path          = "~/Content/Uploads/Category/" + Path.GetFileName(img.FileName);
                cat.cat_image = path;
                cat.admin_ID  = 1; //ToDo
                cat.status    = 1;
                context.categories.Add(cat);
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(cat));
        }
コード例 #9
0
 public ActionResult register(customer cust)
 {
     if (ModelState.IsValid)
     {
         context.customers.Add(cust);
         context.SaveChanges();
         return(RedirectToAction("Login"));
     }
     return(View(cust));
 }
コード例 #10
0
 public ActionResult Edit(userAccount u)
 {
     using (myDbContext db = new myDbContext())
     {
         db.userAccount.Attach(u);
         db.Entry(u).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
コード例 #11
0
 public ActionResult Delete(int id)
 {
     using (myDbContext db = new myDbContext())
     {
         userAccount u = db.userAccount.Single(x => x.UserID == id);
         db.userAccount.Remove(u);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
コード例 #12
0
        public ActionResult Create(TopTenList lmodel, IEnumerable <ListItem> items, IEnumerable <HttpPostedFileBase> file1, HttpPostedFileBase file)
        {
            var currentUser = manager.FindById(User.Identity.GetUserId());

            if (ModelState.IsValid)
            {
                lmodel.ListItems  = items;
                lmodel.AspNetUser = currentUser;

                using (var br = new BinaryReader(file.InputStream))
                {
                    var data = br.ReadBytes(file.ContentLength);
                    lmodel.Image = data;
                }

                db.TopTenList.Add(lmodel);

                var imageList = new List <object>();
                foreach (var j in file1)
                {
                    using (var br = new BinaryReader(j.InputStream))
                    {
                        var data = br.ReadBytes(j.ContentLength);
                        imageList.Add(data);
                    }
                }
                var count = 0;
                foreach (var i in items)
                {
                    i.Image  = (byte[])imageList[count];
                    i.TTList = lmodel;
                    db.List_Items.Add(i);
                    count++;
                }

                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(lmodel));
        }
コード例 #13
0
        public ActionResult Comment(Comment com, Int32 ListId)
        {
            var currentUser = manager.FindById(User.Identity.GetUserId());
            var currentList = db.TopTenList.Find(ListId);

            com.AspNetUser = currentUser;
            com.SharedOn   = DateTime.Now;
            com.TTList     = currentList;
            db.Comments.Add(com);
            db.SaveChanges();

            return(RedirectToAction("Index", "List", null));
        }
コード例 #14
0
 public ActionResult Register(userAccount user)
 {
     if (ModelState.IsValid)
     {
         using (myDbContext db = new myDbContext())
         {
             db.userAccount.Add(user);
             db.SaveChanges();
         }
         ModelState.Clear();
         ViewBag.msg = user.FirstName + " Register successful";
     }
     return(View());
 }
コード例 #15
0
 public ProductController(myDbContext context)
 {
     _context = context;
     if (_context.Products.Count() == 0)
     {
         _context.Products.Add(new Product()
         {
             name  = "San Pham 1",
             price = 1000
         });
         _context.Products.Add(new Product()
         {
             name  = "San Pham 2",
             price = 2000
         });
         _context.SaveChanges();
     }
 }
コード例 #16
0
 public void Add(Sprovider entity)
 {
     db.Sprovider.Add(entity);
     db.SaveChanges();
 }
コード例 #17
0
 public void Add(Order entity)
 {
     db.Order.Add(entity);
     db.SaveChanges();
 }
コード例 #18
0
 public void Add(AspNetUsers entity)
 {
     db.AspNetUsers.Add(entity);
     db.SaveChanges();
 }
コード例 #19
0
 public void Add(Dispute entity)
 {
     db.Dispute.Add(entity);
     db.SaveChanges();
 }
コード例 #20
0
 public void Add(ServiceRequested entity)
 {
     db.ServiceRequested.Add(entity);
     db.SaveChanges();
 }
コード例 #21
0
 public ActionResult SignUp(admin_tbl admin)
 {
     context.admin_tbl.Add(admin);
     context.SaveChanges();
     return(RedirectToAction("Login"));
 }
コード例 #22
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello DAB Assignment");

            //Dummy data for Students
            IList <Student> newStudents = new List <Student>()
            {
                new Student()
                {
                    StudentName = "Karl", StudentAUid = "au123456"
                },
                new Student()
                {
                    StudentName = "Frans", StudentAUid = "au666666"
                },
                new Student()
                {
                    StudentName = "Hans", StudentAUid = "au676767"
                },
                new Student()
                {
                    StudentName = "Bubber", StudentAUid = "au678678"
                },
                new Student()
                {
                    StudentName = "Tobias", StudentAUid = "au696969"
                },
                new Student()
                {
                    StudentName = "Hank", StudentAUid = "au890890"
                },
                new Student()
                {
                    StudentName = "Frank", StudentAUid = "au999999"
                }
            };

            //Dummy data for Courses
            IList <Course> newCourses = new List <Course>()
            {
                new Course()
                {
                    CourseName = "DAB", courseId = "101"
                },
                new Course()
                {
                    CourseName = "NGK", courseId = "102"
                },
                new Course()
                {
                    CourseName = "SWD", courseId = "103"
                }
            };

            //Dummy data for which Courses Students Attends
            IList <Attends> newAttendses = new List <Attends>()
            {
                new Attends()
                {
                    Semester = "4. Semester", Student = newStudents[0], Course = newCourses[0]
                },                                                                                              //Karl attends DAB
                new Attends()
                {
                    Semester = "4. Semester", Student = newStudents[1], Course = newCourses[0]
                },                                                                                              //Frans attends DAB
                new Attends()
                {
                    Semester = "4. Semester", Student = newStudents[0], Course = newCourses[1]
                },                                                                                              //Karl attends NGK
                new Attends()
                {
                    Semester = "4. Semester", Student = newStudents[1], Course = newCourses[2]
                },                                                                                              //Frans attends SWD
                new Attends()
                {
                    Semester = "4. Semester", Student = newStudents[2], Course = newCourses[2]
                },                                                                                              //Hans attends SWD
                new Attends()
                {
                    Semester = "4. Semester", Student = newStudents[0], Course = newCourses[2]
                },                                                                                              //Karl attends SWD
                new Attends()
                {
                    Semester = "4. Semester", Student = newStudents[3], Course = newCourses[0]
                }                                                                                               //Bubber attends DAB
            };

            //Dummy data for Teachers
            IList <Teacher> newTeachers = new List <Teacher>()
            {
                new Teacher()
                {
                    TeacherName = "Henrik Kirk", TeacherAUid = "au700001", Course = newCourses[0]
                },                                                                                                  //Henrik teaches DAB
                new Teacher()
                {
                    TeacherName = "Michael Alrøe", TeacherAUid = "au700002", Course = newCourses[1]
                },                                                                                                  //Alrøe teachers NGK
                new Teacher()
                {
                    TeacherName = "Michael Loft", TeacherAUid = "au700003", Course = newCourses[2]
                }                                                                                                   //Loft teaches SWD
            };

            IList <Exercise> newExercises = new List <Exercise>()
            {
                new Exercise()
                {
                    number = "1", lecture = "EfCore Advanced", helpwhere = "Shannon 03B", Course = newCourses[0], Teacher = newTeachers[0], student = newStudents[0]
                },                                                                                                                                                                  //Karl skal have hjælp til opgave 1 i DAB
                new Exercise()
                {
                    number = "2", lecture = "EfCore Intro", helpwhere = "Shannon 03B", Course = newCourses[0], Teacher = newTeachers[0], student = newStudents[0]
                },                                                                                                                                                                  //Karl skal have hjælp til opgave 2 i DAB
                new Exercise()
                {
                    number = "1", lecture = "UDP", helpwhere = "Edison 114", Course = newCourses[1], Teacher = newTeachers[1], student = newStudents[0]
                },                                                                                                                                                                  //Karl skal have hjælp til opgave 1 i NGK
                new Exercise()
                {
                    number = "2", lecture = "TCP", helpwhere = "Shannon 03B", Course = newCourses[1], Teacher = newTeachers[1], student = newStudents[2]
                },                                                                                                                                                                  //Hans skal have hjælp til opgave 2 i NGK
                new Exercise()
                {
                    number = "3", lecture = "TCP", helpwhere = "Edison 114", Course = newCourses[1], Teacher = newTeachers[1], student = newStudents[0]
                },                                                                                                                                                                  //Karl skal have hjælp til opgave 3 i NGK
                new Exercise()
                {
                    number = "1", lecture = "SOLID", helpwhere = "Shannon 03B", Course = newCourses[2], Teacher = newTeachers[2], student = newStudents[1]
                }                                                                                                                                                                   //Frans skal have hjælp til opgave 1 i SWD
            };

            //Dummy data for Assignments
            IList <Assignment> newAssignments = new List <Assignment>()
            {
                new Assignment()
                {
                    number = "1", lecture = "EfCore Advanced", helpwhere = "Shannon 03B", Teacher = newTeachers[0], Course = newCourses[0]
                },                                                                                                                                              // Aflevering 1 til DAB
                new Assignment()
                {
                    number = "1", lecture = "TCP", helpwhere = "Shannon 03B", Teacher = newTeachers[1], Course = newCourses[1]
                },                                                                                                                                              // Aflevering 1 til NGK
                new Assignment()
                {
                    number = "1", lecture = "SOLID", helpwhere = "Edison 114", Teacher = newTeachers[2], Course = newCourses[2]
                },                                                                                                                                              // Aflevering 1 til SWD
            };

            IList <RequestHelpAssignments> newHelpAssignmentses = new List <RequestHelpAssignments>()
            {
                new RequestHelpAssignments()
                {
                    Student = newStudents[0], Assignment = newAssignments[0], Isactive = true
                },                                                                                                        // Karl arbejeder på Aflevering 1 til DAB
                new RequestHelpAssignments()
                {
                    Student = newStudents[1], Assignment = newAssignments[0], Isactive = true
                },                                                                                                        // Frans arbejeder på Aflevering 1 til DAB
                new RequestHelpAssignments()
                {
                    Student = newStudents[2], Assignment = newAssignments[0], Isactive = true
                },                                                                                                        // Hans arbejeder på Aflevering 1 til DAB
                new RequestHelpAssignments()
                {
                    Student = newStudents[1], Assignment = newAssignments[1], Isactive = true
                },                                                                                                        // Frans arbejeder på Aflevering 1 til NGK
                new RequestHelpAssignments()
                {
                    Student = newStudents[2], Assignment = newAssignments[1], Isactive = true
                },                                                                                                        // Hans arbejeder på Aflevering 1 til NGK
                new RequestHelpAssignments()
                {
                    Student = newStudents[3], Assignment = newAssignments[1], Isactive = true
                },                                                                                                        // Bubber arbejeder på Aflevering 1 til NGK
                new RequestHelpAssignments()
                {
                    Student = newStudents[1], Assignment = newAssignments[2], Isactive = false
                },                                                                                                         // Frans arbejeder på Aflevering 1 til SWD
                new RequestHelpAssignments()
                {
                    Student = newStudents[2], Assignment = newAssignments[2], Isactive = true
                },                                                                                                        // Hans arbejeder på Aflevering 1 til SWD
                new RequestHelpAssignments()
                {
                    Student = newStudents[3], Assignment = newAssignments[2], Isactive = true
                },                                                                                                        // Bubber arbejeder på Aflevering 1 til SWD
            };

            //Main program
            using (var context = new myDbContext())
            {
                Console.WriteLine("");
                Console.WriteLine("Press: a(Adds all dummy data), b(add courses)");
                Console.WriteLine("Press: s(Delete all dummy data)");
                Console.WriteLine("Press: l(list of StudentNames), k(list of courses), j(List of all teachers), g(see which course a student attends)");
                Console.WriteLine("Press: p(To search a specific student), o(To search open help requests for assignments for a student");
                Console.WriteLine("Press: i(To search either which open help request is connected to a teacher or a course)");
                Console.WriteLine("Press: u(To see statistics for a specific course)");
                Console.WriteLine("Creation: m(Student), n(Course), v(Teacher), c(Assignment), q(Exercise) & y(Help request)");
                Console.WriteLine("Press: h(See the help list again)");
                Console.WriteLine("Exit: x");

                while (true)
                {
                    Console.Write("Type Command:");
                    string line = Console.ReadLine();

                    switch (line)
                    {
                    case "a":     //Case a will implement all the dummy data.
                        context.Students.AddRange(newStudents);
                        context.Teachers.AddRange(newTeachers);
                        context.Attends.AddRange(newAttendses);
                        context.Exercises.AddRange(newExercises);
                        context.Assignments.AddRange(newAssignments);
                        context.Courses.AddRange(newCourses);
                        context.RequestHelpAssignments.AddRange(newHelpAssignmentses);
                        context.SaveChanges();
                        break;

                    case "b":     //What are you?
                        break;

                    case "s":     //Case s will delete all the dummy data
                        context.Courses.RemoveRange(newCourses);
                        context.Students.RemoveRange(newStudents);
                        context.Teachers.RemoveRange(newTeachers);
                        context.Exercises.RemoveRange(newExercises);
                        context.Assignments.RemoveRange(newAssignments);
                        context.Attends.RemoveRange(newAttendses);
                        context.RequestHelpAssignments.RemoveRange(newHelpAssignmentses);
                        context.SaveChanges();
                        break;

                    case "l":     //All students
                        foreach (var student in context.Students)
                        {
                            Console.WriteLine(student.StudentName + " " + student.StudentAUid);
                        }
                        break;

                    case "k":     //All Courses
                        foreach (var course in context.Courses)
                        {
                            Console.WriteLine(course.CourseName + " " + course.courseId);
                        }
                        break;

                    case "j":     //All Teachers
                        foreach (var teacher in context.Teachers)
                        {
                            Console.WriteLine(teacher.TeacherName + " " + teacher.TeacherAUid + " " + teacher.courseId);
                        }
                        break;

                    case "g":     //Which course a student attends
                        foreach (var attends in context.Attends)
                        {
                            Console.WriteLine(attends.StudentId + " attends " + attends.CourseId + " during " + attends.Semester);
                        }
                        break;

                    case "p":     //Specific student by AUID
                        Console.WriteLine("Enter the auID of the specific student: ");
                        string IDinput = Console.ReadLine();

                        var user = context.Students.Find(IDinput);
                        Console.WriteLine(user.StudentName + " " + user.StudentAUid + " " + user.StudentExercises);

                        break;

                    case "o":     //Specific help request for a student by AUID
                        Console.WriteLine("Enter the auID of the specific student: ");
                        string IDinput1 = Console.ReadLine();

                        List <RequestHelpAssignments> user1 = context.RequestHelpAssignments
                                                              .Where(a => a.StudentId == IDinput1 && a.Isactive == true)
                                                              .Include(b => b.Student)
                                                              .Include(c => c.Assignment)
                                                              .ToList();

                        foreach (var s in user1)
                        {
                            Console.WriteLine("Student " + s.Student.StudentName + " needs help with assignment " + s.Assignment.lecture + " in building " + s.Assignment.helpwhere);
                        }
                        break;

                    case "i":     //See all help request for a given Teacher or Course
                        Console.WriteLine("Enter teacherID or courseID: ");
                        string NewInput = Console.ReadLine();

                        List <RequestHelpAssignments> user2 = context.RequestHelpAssignments
                                                              .Where(a => a.Assignment.Teacher.TeacherAUid == NewInput && a.Isactive == true ||
                                                                     a.Assignment.Course.courseId == NewInput && a.Isactive == true)
                                                              .Include(a => a.Assignment)
                                                              .ThenInclude(b => b.Teacher)
                                                              .Include(a => a.Assignment)
                                                              .ThenInclude(b => b.Course)
                                                              .Include(a => a.Student)
                                                              .ToList();

                        foreach (var b in user2)
                        {
                            Console.WriteLine("Student " + b.Student.StudentName + " needs help with assignment " + b.Assignment.lecture + " in building " + b.Assignment.helpwhere);
                        }
                        break;

                    case "u":     //Statistics of requests for a course
                        Console.WriteLine("Enter courseID: ");
                        string CourseStats = Console.ReadLine();

                        List <RequestHelpAssignments> OpenReq = context.RequestHelpAssignments
                                                                .Where(a => a.Assignment.Course.courseId == CourseStats && a.Isactive == true)
                                                                .Include(a => a.Assignment)
                                                                .ThenInclude(b => b.Course)
                                                                .ToList();

                        List <RequestHelpAssignments> ClosedReq = context.RequestHelpAssignments
                                                                  .Where(a => a.Assignment.Course.courseId == CourseStats && a.Isactive == false)
                                                                  .Include(a => a.Assignment)
                                                                  .ThenInclude(b => b.Course)
                                                                  .ToList();

                        var CourseName = context.Courses.Find(CourseStats);

                        Console.WriteLine("For the course: " + CourseName.CourseName);
                        Console.WriteLine("The amount of open request: " + OpenReq.Count + " and closed request: " + ClosedReq.Count);
                        int Total = OpenReq.Count + ClosedReq.Count;
                        Console.WriteLine("Total amount request: " + Total);
                        break;

                    case "m":     //Create student
                        Student newstudent = InputStudent();
                        context.Students.Add(newstudent);
                        context.SaveChanges();
                        break;

                    case "n":     //Create Course
                        Course newCourse = InputCourse();
                        context.Courses.Add(newCourse);
                        context.SaveChanges();
                        break;

                    case "v":     //Create Teacher
                        Teacher newTeacher = InputTeacher(context);
                        context.Teachers.Add(newTeacher);
                        context.SaveChanges();
                        break;

                    case "c":     //Create Assignment
                        Assignment newAssignment = InputAssignment(context);
                        context.Assignments.Add(newAssignment);
                        context.SaveChanges();
                        break;

                    case "q":     //Create Exercise
                        Exercise newExercise = InputExercise(context);
                        context.Exercises.Add(newExercise);
                        context.SaveChanges();
                        break;

                    case "y":     //Create RequestHelpAssignments
                        RequestHelpAssignments newreRequestHelpAssignments = InputRequestHelpAssignments(context);
                        context.RequestHelpAssignments.Add(newreRequestHelpAssignments);
                        context.SaveChanges();
                        break;

                    case "h":     //Console inputs
                        Console.WriteLine("");
                        Console.WriteLine("Press: a(Adds all dummy data), b(add courses)");
                        Console.WriteLine("Press: s(Delete all dummy data)");
                        Console.WriteLine("Press: l(list of StudentNames), k(list of courses), j(List of all teachers), g(see which course a student attends)");
                        Console.WriteLine("Press: p(To search a specific student), o(To search open help requests for assignments for a student");
                        Console.WriteLine("Press: i(To search either which open help request is connected to a teacher or a course)");
                        Console.WriteLine("Press: u(To see statistics for a specific course)");
                        Console.WriteLine("Creation: m(Student), n(Course), v(Teacher), c(Assignment), q(Exercise) & y(Help request)");
                        Console.WriteLine("Press: h(See the help list again)");
                        Console.WriteLine("Exit: x");
                        break;

                    case "x":     //Case x will exit the while loop and close the program
                        Console.WriteLine("Exiting..");
                        return;

                    default:     //In case a case which is not implemented is used
                        Console.WriteLine("Unknown command");
                        break;
                    }
                }
            }
        }
コード例 #23
0
 public void Add(Category entity)
 {
     db.Category.Add(entity);
     db.SaveChanges();
 }
コード例 #24
0
 public void Add(Service entity)
 {
     db.Service.Add(entity);
     db.SaveChanges();
 }