Beispiel #1
0
        public ActionResult DeleteUploadConfirmed(int id)
        {
            var deleted = db2.FileUploads.Find(id);

            db2.FileUploads.Remove(deleted);
            db2.SaveChanges();

            return(RedirectToAction("ManageUpload"));
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "id,StudentId,ModuleId,EnrollmentDate,Grade")] Enrollment enrollment)
        {
            if (ModelState.IsValid)
            {
                db.Enrollments.Add(enrollment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ModuleId  = new SelectList(db.Modules, "id", "ModuleName", enrollment.ModuleId);
            ViewBag.StudentId = new SelectList(db.Students, "id", "RegistrationID", enrollment.StudentId);
            return(View(enrollment));
        }
        public IHttpActionResult CreateModule(ModuleDTO moduleDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var module = Mapper.Map <ModuleDTO, Module>(moduleDto);

            _attendanceDb.Modules.Add(module);
            _attendanceDb.SaveChanges();

            moduleDto.id = module.id;

            return(Created(new Uri(Request.RequestUri + "/" + module.id), moduleDto));
        }
Beispiel #4
0
        public IHttpActionResult CreateStudent(StudentDTO studentDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var student = Mapper.Map <StudentDTO, Student>(studentDto);

            _attendanceDb.Students.Add(student);
            _attendanceDb.SaveChanges();

            studentDto.id = student.id;

            return(Created(new Uri(Request.RequestUri + "/" + student.id), studentDto));
        }
Beispiel #5
0
        public ActionResult Upload(HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file == null)
                {
                    ModelState.AddModelError("File", "You haven't choice any file.");
                }
                else if (file.ContentLength > 0)
                {
                    int      MaxContentLength      = 1024 * 1024 * 3; //3 MB
                    string[] AllowedFileExtensions = new string[] { ".jpg", ".gif", ".png" };

                    if (!AllowedFileExtensions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.'))))
                    {
                        ModelState.AddModelError("File", "Please file of type: " + string.Join(", ", AllowedFileExtensions));
                    }

                    else if (file.ContentLength > MaxContentLength)
                    {
                        ModelState.AddModelError("File", "Your file is too large, maximum allowed size is: " + MaxContentLength + " MB");
                    }
                    else
                    {
                        //TO:DO
                        var        fileName = Path.GetFileName(file.FileName);
                        var        userid   = User.Identity.GetUserId();
                        var        pathDB   = Path.Combine(("~/Content/Upload"), fileName);
                        var        path     = Path.Combine(Server.MapPath("~/Content/Upload"), fileName);
                        var        filesize = file.ContentLength;
                        FileUpload uploads  = new FileUpload {
                            Filename = fileName, Filepath = pathDB, Userid = userid
                        };
                        contexts.FileUploads.Add(uploads);
                        contexts.SaveChanges();
                        file.SaveAs(path);
                        ModelState.Clear();
                        ViewBag.Message = "File uploaded successfully";
                    }
                }
            }
            return(View());
        }
Beispiel #6
0
        public ActionResult FileUpload(HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file == null)
                {
                    ModelState.AddModelError("File", "Please Upload Your file");
                }
                else if (file.ContentLength > 0)
                {
                    int      MaxContentLength      = 1024 * 1024 * 3; //3 MB
                    string[] AllowedFileExtensions = new string[] { ".jpg", ".gif", ".png", ".pdf" };

                    if (!AllowedFileExtensions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.'))))
                    {
                        ModelState.AddModelError("File", "Please file of type: " + string.Join(", ", AllowedFileExtensions));
                    }

                    else if (file.ContentLength > MaxContentLength)
                    {
                        ModelState.AddModelError("File", "Your file is too large, maximum allowed size is: " + MaxContentLength + " MB");
                    }
                    else
                    {
                        using (AttendanceDB ucok = new AttendanceDB())
                        {
                            var        userId       = User.Identity.GetUserId();
                            var        fileName     = Path.GetFileName(file.FileName);
                            var        pathdatabase = Path.Combine(("~/Content/Upload"), fileName);
                            var        path         = Path.Combine(Server.MapPath("~/Content/Upload"), fileName);
                            var        fileSize     = file.ContentLength;
                            FileUpload jin          = new FileUpload {
                                FileName = fileName, FilePath = pathdatabase, UserId = userId
                            };



                            ViewBag.Message = "File uploaded successfully";
                            ucok.FileUploads.Add(jin);
                            ucok.SaveChanges();
                            file.SaveAs(path);
                            ModelState.Clear();
                        }


                        //TO:DO
                    }
                }
            }
            return(View());
        }
Beispiel #7
0
        public ActionResult Approve(int id)
        {
            FileUpload cari = ucok2.FileUploads.Find(id);

            if (cari.approve == true)
            {
                cari.approve = false;
            }
            else
            {
                cari.approve = true;
            }
            ucok2.Entry(cari).State = EntityState.Modified;
            ucok2.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #8
0
 public void Add(Student p)
 {
     context.Students.Add(p);
     context.SaveChanges();
 }
 public void Add(Lecturer p)
 {
     context.Lecturers.Add(p);
     context.SaveChanges();
 }