Esempio n. 1
0
        // GET: eLearning/CourseContents/Create
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                TempData["ErrorMessage"] = "Could not find the content.";

                return(Redirect(Request.UrlReferrer.ToString()));
            }

            var model = await TryGetContent(id.Value);

            await GetAllQuestions(model.CourseId, model.ContentQuestionId != null?model.ContentQuestionId.Value : -1);

            if (model.ContentType == CourseContentType.Audio)
            {
                await GetAllAudio(model.CourseId, model.ContentFileId != null?model.ContentFileId.Value : -1);
            }

            if (model.ContentType == CourseContentType.Document)
            {
                await GetAllDocument(model.CourseId, model.ContentFileId != null?model.ContentFileId.Value : -1);

                if (model.DocumentType == DocumentType.UseSlideshare)
                {
                    if (!model.Url.Contains("embed_code"))
                    {
                        model.Url = await SlideshareHelper.GetEmbedCode(model.Url);
                    }
                }
            }

            return(View(model));
        }
Esempio n. 2
0
        public async Task <string> GetSlideshare(string newUrl)
        {
            if (!newUrl.Contains("embed_code"))
            {
                var result = await SlideshareHelper.GetEmbedCode(newUrl);

                return(result);
            }

            return(newUrl);
        }
Esempio n. 3
0
        public async Task <ActionResult> Edit(CreateOrEditContentModel model, string SubmitType = "Save")
        {
            if (ModelState.IsValid)
            {
                model.CreatedBy = CurrentUser.UserId.Value;

                var currentFileName = model.File;
                model.File = null;
                var modelFileDocument = model.FileDocument;

                // check slideshare url and change to embed code
                if (model.ContentType == CourseContentType.Document)
                {
                    await GetAllDocument(model.CourseId, model.ContentFileId != null?model.ContentFileId.Value : -1);

                    if (model.DocumentType == DocumentType.UseSlideshare)
                    {
                        if (!model.Url.Contains("embed_code"))
                        {
                            model.Url = await SlideshareHelper.GetEmbedCode(model.Url);
                        }
                    }
                }

                if (model.IsFeedbackOn > 0)
                {
                    if (model.FeedbackId == null)
                    {
                        FeedbackCreateModel _new = new FeedbackCreateModel();
                        _new.CreatedBy = model.CreatedBy;
                        _new.Created   = model.CreatedDate;

                        var _createFeedback = await WepApiMethod.SendApiAsync <int>(HttpVerbs.Post, ContentApiUrl.CreateFeedback, _new);

                        if (_createFeedback.isSuccess)
                        {
                            model.FeedbackId = _createFeedback.Data;
                        }
                    }
                }

                var response = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Post, ContentApiUrl.Edit, model);

                if (response.isSuccess)
                {
                    TempData["SuccessMessage"] = "Content successfully edited.";

                    await LogActivity(Modules.Learning, "Edit content : " + model.Title);

                    // Check if this creation include fileupload, which will require us to save the file
                    model.File = currentFileName;
                    if (((model.ContentType == CourseContentType.Video && model.VideoType == VideoType.UploadVideo) ||
                         (model.ContentType == CourseContentType.Audio && model.AudioType == AudioType.UploadAudio) ||
                         (model.ContentType == CourseContentType.Document && model.DocumentType == DocumentType.UploadDocument) ||
                         (model.ContentType == CourseContentType.Flash) ||
                         (model.ContentType == CourseContentType.Pdf) ||
                         (model.ContentType == CourseContentType.Powerpoint)) &&
                        model.File != null)
                    {
                        // upload the file
                        var result = await new FileController().UploadToApi <List <FileDocumentModel> >(model.File);

                        if (result.isSuccess)
                        {
                            var data = result.Data;

                            var fileDocument = data[0];

                            fileDocument.FileType        = model.ContentType.ToString();
                            fileDocument.CreatedBy       = CurrentUser.UserId.Value;
                            fileDocument.ContentFileType = model.FileType;
                            fileDocument.CourseId        = model.CourseId;
                            fileDocument.ContentId       = model.Id;

                            if (model.ContentType == CourseContentType.Audio)
                            {
                                fileDocument.ContentFileType = FileType.Audio;
                            }

                            if (model.ContentType == CourseContentType.Video)
                            {
                                fileDocument.ContentFileType = FileType.Video;
                            }

                            if (model.ContentType == CourseContentType.Document)
                            {
                                fileDocument.ContentFileType = FileType.Document;
                            }

                            var resultUpload = await WepApiMethod.SendApiAsync <string>(HttpVerbs.Post, FileApiUrl.UploadInfo, fileDocument);

                            if (resultUpload.isSuccess)
                            {
                                model.ContentFileId = int.Parse(resultUpload.Data);
                            }
                            else
                            {
                                TempData["ErrorMessage"] = "Cannot upload file";
                            }
                        }
                    }

                    if (SubmitType.Equals("SaveAndView"))
                    {
                        return(RedirectToAction("View", "CourseContents", new { area = "eLearning", @id = model.Id }));
                    }
                    else
                    {
                        return(RedirectToAction("Content", "CourseModules", new { area = "eLearning", @id = model.CourseModuleId }));
                    }
                }
            }

            TempData["ErrorMessage"] = "Cannot edit content.";

            await GetAllQuestions(model.CourseId);

            return(View(model));
        }