Пример #1
0
 public ActionResult AddVideo(VideoViewModel model, string[] names)
 {
     if (ModelState.IsValid)
     {
         List <Skill> skills = new List <Skill>();
         foreach (var item in names.Where(x => x != "false"))
         {
             skills.Add(skillService.Get(item));
         }
         try
         {
             materialService.CreateVideo(model.Name,
                                         model.Link,
                                         model.Length,
                                         model.Quality,
                                         skills);
             return(RedirectToAction("Index", "Home"));
         }
         catch (ArgumentException ex)
         {
             ViewBag.Error = ex.Message;
             return(View("Error"));
         }
     }
     else
     {
         ViewBag.Skills = skillService.Get();
         return(View(model));
     }
 }
        public string MaterialInfoInput()
        {
            if (session.IsAuthorised)
            {
                materialService.ShowMaterials();

                string name = string.Empty;
                string link = string.Empty;

                Console.WriteLine("Enter material type:\n 1. Video\n 2.Article\n 3.Book");

                while (true)
                {
                    var materialType = Console.ReadLine();
                    if (string.IsNullOrEmpty(materialType))
                    {
                        Console.WriteLine(@"Error! {0}", "Enter the material type!");
                    }

                    if (materialType == "1" || materialType == "Video")
                    {
                        string length  = string.Empty;
                        string quality = string.Empty;

                        var materialDTO = BasicInfoInput();

                        length = InfoUnit.GetInfoUnit(length,
                                                      x => !string.IsNullOrEmpty(x.ToString()),
                                                      "Enter video length!",
                                                      @"Error! Enter the correct length!").ToString();

                        quality = InfoUnit.GetInfoUnit(quality,
                                                       x => !string.IsNullOrEmpty(x.ToString()),
                                                       "Enter video quality!",
                                                       @"Error! Enter the correct quality!").ToString();

                        materialService.CreateVideo(materialDTO.Name, materialDTO.Link, length, quality, materialDTO.Skills);
                        return(materialDTO.Name);
                    }

                    if (materialType == "2" || materialType == "Article")
                    {
                        string publishDate = string.Empty;

                        var materialDTO = BasicInfoInput();

                        publishDate = InfoUnit.GetInfoUnit(publishDate,
                                                           x => !string.IsNullOrEmpty(x.ToString()),
                                                           "Enter publish date!",
                                                           @"Error! Enter the correct publish date!").ToString();

                        materialService.CreateArticle(materialDTO.Name, materialDTO.Link, publishDate, materialDTO.Skills);
                        return(materialDTO.Name);
                    }

                    if (materialType == "3" || materialType == "Book")
                    {
                        string author     = string.Empty;
                        int    pageNumber = 0;
                        string format     = string.Empty;
                        string year       = string.Empty;

                        var materialDTO = BasicInfoInput();

                        author = InfoUnit.GetInfoUnit(author,
                                                      x => !string.IsNullOrEmpty(x.ToString()),
                                                      "Enter author name!",
                                                      @"Error! Enter the correct author!").ToString();

                        pageNumber = Convert.ToInt32
                                     (
                            InfoUnit.GetInfoUnit
                            (
                                pageNumber,
                                x => !string.IsNullOrEmpty(x.ToString()),
                                "Enter page number!",
                                @"Error! Enter the correct page number!"
                            )
                                     );

                        format = InfoUnit.GetInfoUnit(format,
                                                      x => !string.IsNullOrEmpty(x.ToString()),
                                                      "Enter format!",
                                                      @"Error! Enter the correct format!").ToString();

                        year = InfoUnit.GetInfoUnit(year,
                                                    x => !string.IsNullOrEmpty(x.ToString()),
                                                    "Enter year!",
                                                    @"Error! Enter the correct year!").ToString();

                        materialService.CreateBook(materialDTO.Name, materialDTO.Link, author, pageNumber,
                                                   format, year, materialDTO.Skills);
                        return(materialDTO.Name);
                    }
                }
            }
            else
            {
                Console.WriteLine("You need to authorize");
                return(null);
            }
        }