Ejemplo n.º 1
0
        public ActionResult Create(CreateDocumentViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var newDocument = new UserDocument()
                {
                    Description = vm.Description,
                    Name        = vm.file.FileName,
                    UploadTime  = DateTime.Now,
                    /*UserId = vm.EnitityId,*/
                };

                newDocument.UserId = _userManager.GetUserId(User);

                using (var memoryStream = new MemoryStream())
                {
                    vm.file.CopyTo(memoryStream);
                    newDocument.DocumentData = memoryStream.ToArray();
                }

                //_context.UserDocument.Add(newDocument);
                //_context.SaveChanges();

                //Can't get it to accept nameof(Details) for some reason
                return(RedirectToAction("Details", "StudentAdmin", new { id = vm.EnitityId }));
            }
            else
            {
                return(View(vm));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Create(CreateDocumentViewModel viewModel)
        {
            var user = await GetApplicationUser();

            if (user == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var document = new Document()
            {
                Name       = viewModel.Name,
                CreatedAt  = DateTime.Now,
                ModifiedAt = DateTime.Now,
                Body       = viewModel.Body,
                Owner      = user,
                Index      = viewModel.Index,
                Title      = viewModel.Title
            };

            db.Documents.Add(document);
            await db.SaveChangesAsync();

            return(RedirectToAction("Details", new { name = viewModel.Name }));
        }
Ejemplo n.º 3
0
        public IActionResult Create(CreateDocumentViewModel vm)
        {
            var presenter = _presenterFactory.Create(MessageHandler, ErrorHandler);

            if (!ModelState.IsValid)
            {
                return(View(presenter.Present(vm)));
            }

            var request = vm.ToRequest(CurrentUserId);

            try
            {
                var uc       = _useCaseFactory.Create;
                var response = uc.Execute(request);
                return(RedirectToAction(nameof(Index), new { id = presenter.Present(response) }));
            }
            catch (InvalidRequestException ire)
            {
                presenter.PresentErrors(ire.Message, ire.Errors);
                return(View(presenter.Present(vm)));
            }
            catch (Exception e)
            {
                presenter.PresentMessage(MessageType.Error, e.Message);
                return(View(presenter.Present(vm)));
            }
        }
        public ActionResult AddDocumentActivity(int id)
        {
            CreateDocumentViewModel cdvm = new CreateDocumentViewModel {
                Id = id, DocumentType = CreateDocumentType.Activity
            };

            ViewBag.Target = "Activity";
            return(PartialView("CreateDocumentPartial", cdvm));
        }
        public ActionResult AddDocumentModule(int id)
        {
            CreateDocumentViewModel cdvm = new CreateDocumentViewModel {
                Id = id, DocumentType = CreateDocumentType.Module
            };

            ViewBag.Target = "Module";
            return(PartialView("CreateDocumentPartial", cdvm));
        }
Ejemplo n.º 6
0
        // GET: CourseDocument/Create
        public ActionResult Create(int id)
        {
            var vm = new CreateDocumentViewModel()
            {
                EnitityId = id
            };

            return(View(vm));
        }
Ejemplo n.º 7
0
        // GET: CourseDocument/Create
        public ActionResult Create(int id)
        {
            var vm = new CreateDocumentViewModel()
            {
                EnitityId = id
            };

            ViewData["Title"]     = "Add Course Document";
            ViewData["parentUrl"] = $"/Course/Details/{id}";
            return(View("_CreateDocumentPartial", vm));
        }
 public static CreateDocumentRequest ToRequest(this CreateDocumentViewModel vm, string userId)
 {
     return(new CreateDocumentRequest(userId)
     {
         ProjectId = Identity.FromString(vm.Project.Id),
         Name = vm.Name,
         Content = vm.Content,
         Kind = Enum.Parse <DocumentKind>(vm.DocumentType),
         Links = vm.Links,
     });
 }
        public IActionResult CreateDocument(int id)
        {
            var createDocumentViewModel = new CreateDocumentViewModel {
                TopicId       = id,
                DocumentTypes = _context.DocumentType.Select(dt => new SelectListItem {
                    Text  = dt.Name,
                    Value = dt.Id.ToString()
                })
            };

            return(View(createDocumentViewModel));
        }
Ejemplo n.º 10
0
        public ActionResult Create(CreateDocumentViewModel vm)
        {
            if (ModelState.IsValid)
            {
                if (vm.file is null)
                {
                    ModelState.AddModelError("file", "File can't be empty!");
                    ViewData["parentUrl"] = $"/Activity/Details/{vm.Id}";
                    ViewData["Title"]     = "Add Activity Document";
                    return(View("_CreateDocumentPartial", vm));
                }
                var newDocument = new ActivityDocument()
                {
                    Description = vm.Description,
                    Name        = vm.file.FileName,
                    UploadTime  = DateTime.Now,
                    ActivityId  = vm.EnitityId,
                };
                if (newDocument.Description is null)
                {
                    newDocument.Description = "none";
                }
                newDocument.UserId = _userManager.GetUserId(User);

                using (var memoryStream = new MemoryStream())
                {
                    vm.file.CopyTo(memoryStream);
                    newDocument.DocumentData = memoryStream.ToArray();
                }

                _context.ActivityDocument.Add(newDocument);
                _context.SaveChanges();

                //Can't get it to accept nameof(Details) for some reason

                if (User.IsInRole("Teacher"))
                {
                    TempData["AlertMsg"] = "Document added";
                    return(RedirectToAction("Details", "Activity", new { id = vm.EnitityId }));
                }
                else
                {
                    TempData["AlertMsg"] = "Assignment uploaded - good luck!";
                    return(RedirectToAction("Index", "Student"));
                }
            }
            else
            {
                ViewData["parentUrl"] = $"/Activity/Details/{vm.Id}";
                ViewData["Title"]     = "Add Activity Document";
                return(View("_CreateDocumentPartial", vm));
            }
        }
Ejemplo n.º 11
0
        public ActionResult CreateStudent(int id)
        {
            var vm = new CreateDocumentViewModel()
            {
                EnitityId = id
            };
            var act = _context.Activities.FirstOrDefault(a => a.Id == id);

            ViewData["Title"]     = $"Assignment deadline: {act.EndDate.ToShortDateString() }";
            ViewData["parentUrl"] = $"/";
            return(View("_CreateDocumentPartial", vm));
        }
Ejemplo n.º 12
0
        //
        // GET: /Document/

        public ActionResult Select(int id)
        {
            CreateDocumentViewModel model = new CreateDocumentViewModel();

            model.tipstaffRecord = db.TipstaffRecord.Find(id);
            if (model.tipstaffRecord.caseStatus.sequence > 3)
            {
                TempData["UID"] = model.tipstaffRecord.UniqueRecordID;
                return(RedirectToAction("ClosedFile", "Error"));
            }

            string docType = genericFunctions.TypeOfTipstaffRecord(model.tipstaffRecord);

            model.TemplatesForRecordType = db.Templates.Where(t => (t.Discriminator == docType || t.Discriminator == "All") && t.active).OrderBy(t => t.Discriminator).ThenBy(x => x.templateName);
            return(View(model));
        }
        public ActionResult AddDocument(CreateDocumentViewModel cdvm, HttpPostedFileBase upload)
        {
            int id = -1;

            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    UserStore <ApplicationUser>   us = new UserStore <ApplicationUser>(db);
                    UserManager <ApplicationUser> um = new UserManager <ApplicationUser>(us);

                    var document = new DocumentModels
                    {
                        Name        = upload.FileName,
                        TimeStamp   = DateTime.Now,
                        ContentType = upload.ContentType,
                    };
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        document.Contents = reader.ReadBytes(upload.ContentLength);
                    }
                    switch (cdvm.DocumentType)
                    {
                    case CreateDocumentType.Course:
                        db.Courses.FirstOrDefault(c => c.Id == cdvm.Id).Documents.Add(document);
                        db.SaveChanges();
                        return(RedirectToAction("DocumentCourseList", new { id = cdvm.Id }));

                    case CreateDocumentType.Module:
                        db.Modules.FirstOrDefault(c => c.Id == cdvm.Id).Documents.Add(document);
                        db.SaveChanges();
                        return(RedirectToAction("DocumentModuleList", new { id = cdvm.Id }));

                    case CreateDocumentType.Activity:
                        db.Activities.FirstOrDefault(c => c.Id == cdvm.Id).Documents.Add(document);
                        db.SaveChanges();
                        return(RedirectToAction("DocumentActivityList", new { id = cdvm.Id }));
                    }
                }
            }

            return(RedirectToAction("Course", "Teacher", new { id = id }));
        }
        public IActionResult CreateDocument(CreateDocumentViewModel document)
        {
            if (document.DocumentType == (int)ProjectEnum.DocumentType.PDF)
            {
                ModelState.Remove("Url");
            }
            else if (document.DocumentType == (int)ProjectEnum.DocumentType.Video)
            {
                ModelState.Remove("File");
            }

            if (ModelState.IsValid)
            {
                if (document.DocumentType == (int)ProjectEnum.DocumentType.PDF)
                {
                    var fileName = document.File.FileName;
                    var trainingFilesFolderPath = Path.Combine(_hostingEnvironment.WebRootPath, "trainingfiles");
                    var filePath = Path.Combine(trainingFilesFolderPath, fileName);
                    if (!_context.Document.Any(d => d.Path == filePath))
                    {
                        using (var fileStream = new FileStream(filePath, FileMode.Create))
                        {
                            document.File.CopyTo(fileStream);
                        }
                        _context.Document.Add(new Documents
                        {
                            DocumentTypeId = document.DocumentType,
                            Path           = Path.Combine("/trainingfiles/", fileName),
                            Name           = document.Name,
                            TopicId        = document.TopicId
                        });

                        _context.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ModelState.AddModelError("File", "That file is already used in the package");
                    }
                }
                else if (document.DocumentType == (int)ProjectEnum.DocumentType.Video)
                {
                    // COnvert the youtube url into an embed url
                    try
                    {
                        ConvertToYoutubeEmbed(document.Url);

                        _context.Document.Add(new Documents
                        {
                            DocumentTypeId = document.DocumentType,
                            Path           = document.Url,
                            Name           = document.Name,
                            TopicId        = document.TopicId
                        });

                        _context.SaveChanges();

                        return(RedirectToAction("Index"));
                    }
                    catch (ArgumentException ex)
                    {
                        ModelState.AddModelError("Url", "Invalid YouTube video URL");
                    }
                }
            }

            document.DocumentTypes = _context.DocumentType.Select(dt => new SelectListItem
            {
                Text  = dt.Name,
                Value = dt.Id.ToString()
            });
            return(View(document));
        }
Ejemplo n.º 15
0
 public CreateDocumentViewModel Present(CreateDocumentViewModel vm)
 {
     vm.DocumentTypes = DocumentTypes();
     return(vm);
 }
 public CreateDocumentPage(CreateDocumentViewModel viewModel) : base(viewModel)
 {
     this.viewModel = viewModel;
 }
Ejemplo n.º 17
0
        // public ActionResult Create([Bind(Include = "Id,Name,Url,Description,Timestamp,Deadline,UserId,GroupId,CourseOccasionId,ActivityId")] Document document, HttpPostedFileBase Name)



        public ActionResult upload([Bind(Include = "Name,Description,GroupId,CourseOccasionId,ActivityId,Deadline")] CreateDocumentViewModel document, HttpPostedFileBase Name)
        {
            var manager     = new UserManager <LMS_Lexicon2015.Models.ApplicationUser>(new Microsoft.AspNet.Identity.EntityFramework.UserStore <LMS_Lexicon2015.Models.ApplicationUser>(new LMS_Lexicon2015.Models.ApplicationDbContext()));
            var currentUser = manager.FindById(User.Identity.GetUserId());


            if (Name == null)
            { // glömt själva filen
                ViewBag.GroupId          = document.GroupId;
                ViewBag.CourseOccasionId = document.CourseOccasionId;
                //ViewBag.ActivityId = document.ActivityId;
                ViewBag.view = (string)TempData["view"];

                ModelState.AddModelError("", "Du har glömt själva filen");
                return(View(document));
            }

            if (ModelState.IsValid)
            {
                var    view          = (string)TempData["view"];
                var    dbFileName    = Name.FileName;
                string fileExtension = Name.FileName.Split('.').Last();

                string fileName     = Guid.NewGuid().ToString() + '.' + fileExtension;
                var    fileSavePath = Path.Combine(Server.MapPath("/Files"), fileName);
                Name.SaveAs(fileSavePath);


                if (view == "Activities" && User.IsInRole("Elev"))
                {
                    string fileNameElev = Name.FileName.Split('.').First();
                    dbFileName = fileNameElev + "-" + currentUser.FirstName + "-" + currentUser.LastName + '.' + fileExtension;
                }

                var doc = new Document
                {
                    //Name = Name.FileName,
                    Name = dbFileName,
                    //Url = fileSavePath,
                    Url              = fileName,
                    Description      = document.Description,
                    Timestamp        = DateTime.Now,
                    Deadline         = document.Deadline,
                    UserId           = User.Identity.GetUserId(),
                    GroupId          = document.GroupId,
                    CourseOccasionId = document.CourseOccasionId,
                    ActivityId       = document.ActivityId
                };

                db.Documents.Add(doc);
                db.SaveChanges();



                if (view == "Group")
                {
                    return(RedirectToAction("Details/" + document.GroupId, "Groups"));
                }
                else if (view == "Course")
                {
                    return(RedirectToAction("Details/" + document.CourseOccasionId + "/" + document.GroupId, "CourseOccasions"));
                }
                else if (view == "Activities")
                {
                    return(RedirectToAction("Details/" + document.ActivityId + "/" + document.CourseOccasionId + "/" + document.GroupId, "Activities"));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.GroupId          = document.GroupId;
            ViewBag.CourseOccasionId = document.CourseOccasionId;
            ViewBag.view             = (string)TempData["view"];

            return(View(document));
        }