Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,IsEnabled,TopicNumber,Notes,ModuleId,Summary,Title,DateCreated,UserCreated,DateModified,UserModified,VideoUrl")] AdmTopic admTopic)
        {
            if (id != admTopic.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(admTopic);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AdmTopicExists(admTopic.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ModuleId"] = new SelectList(_context.AdmModules, "ModuleId", "Title", admTopic.ModuleId);
            return(View(admTopic));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Id,IsEnabled,TopicNumber,Notes,ModuleId,Summary,Title,DateCreated,UserCreated,DateModified,UserModified,VideoUrl")] AdmTopic admTopic)
        {
            if (ModelState.IsValid)
            {
                //List<TopicFiles> fileDetails = new List<TopicFiles>();
                //for (int i = 0; i < Request.Files.Count; i++)
                //{
                //    var file = Request.Files[i];

                //    if (file != null && file.ContentLength > 0)
                //    {
                //        var fileName = Path.GetFileName(file.FileName);
                //        TopicFiles fileDetail = new TopicFiles()
                //        {
                //            FileName = fileName,
                //            Extension = Path.GetExtension(fileName),
                //            Id = Guid.NewGuid()
                //        };
                //        fileDetails.Add(fileDetail);

                //        var path = Path.Combine(Server.MapPath("~/App_Data/Upload/"), fileDetail.Id + fileDetail.Extension);
                //        file.SaveAs(path);
                //    }
                //}

                //admTopic.TopicFiles = fileDetails;

                _context.Add(admTopic);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ModuleId"] = new SelectList(_context.AdmModules, "ModuleId", "Title", admTopic.ModuleId);
            return(View(admTopic));
        }
Beispiel #3
0
        public async Task <IActionResult> Details(int id, [Bind("Id,IsEnabled,TopicNumber,Notes,ModuleId,Summary,Title,DateCreated,UserCreated,DateModified,UserModified,VideoUrl")] AdmTopic admTopic, List <IFormFile> files)
        {
            if (id != admTopic.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (files != null && files.Count > 0)
                    {
                        string folderName  = "Upload";
                        string webRootPath = _hostingEnvironment.WebRootPath;
                        string newPath     = Path.Combine(webRootPath, folderName);
                        if (!Directory.Exists(newPath))
                        {
                            Directory.CreateDirectory(newPath);
                        }
                        foreach (IFormFile item in files)
                        {
                            if (item.Length > 0)
                            {
                                string fileName = ContentDispositionHeaderValue.Parse(item.ContentDisposition).FileName.Trim('"');
                                string fullPath = Path.Combine(newPath, fileName);
                                using (var stream = new FileStream(fullPath, FileMode.Create))
                                {
                                    item.CopyTo(stream);
                                }
                            }
                        }

                        _context.Update(admTopic);
                        await _context.SaveChangesAsync();

                        return(this.Content("Success"));
                    }
                    return(this.Content("Fail"));
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AdmTopicExists(admTopic.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            ViewData["ModuleId"] = new SelectList(_context.AdmModules, "ModuleId", "Title", admTopic.ModuleId);
            return(View(admTopic));
        }