// GET: /TVProgram/Details/<id>
        public ActionResult Details(int id)
        {
            // Get tv progarm with the passed id from database
            TVProgram tvprogram = _context.TVPrograms.Include("Owner").SingleOrDefault(m => m.Id == id);

            // If there is acctually a matching entry
            // in the database
            if (tvprogram != null)
            {
                // Pass the tv program and the current user id
                // to the view through the ViewModel
                TVProgramHomeViewModel model = new TVProgramHomeViewModel()
                {
                    tvprogram     = tvprogram,
                    currentUserId = User.Identity.IsAuthenticated ? User.Identity.GetUserId() : ""
                };
                return(View(model));
            }
            else
            {
                // If there is no such tv program in database
                // redirect to the Index action of TVProgram
                // controller
                return(RedirectToAction("Index"));
            }
        }
Ejemplo n.º 2
0
 private void Bind()
 {
     if (!Id.Equals(Guid.Empty))
     {
         Page.Title = "编辑电视台视频二级";
         TVProgram bll   = new TVProgram();
         var       model = bll.GetModel(Id);
         if (model != null)
         {
             txtName.Value       = model.ProgramName;
             hId.Value           = Id.ToString();
             hHWid.Value         = model.HWTVId.ToString();
             txtSort.Value       = model.Sort.ToString();
             txtProgramURL.Value = model.ProgramAddress;
             txtTVScID.Value     = model.TVScID;
             if (model.IsDisable)
             {
                 rdFalse.Checked = false;
                 rdTrue.Checked  = true;
             }
             else
             {
                 rdFalse.Checked = true;
                 rdTrue.Checked  = false;
             }
         }
     }
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> PutTVProgram([FromRoute] int id, [FromBody] TVProgram tVProgram)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tVProgram.Id)
            {
                return(BadRequest());
            }

            _context.Entry(tVProgram).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TVProgramExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public ActionResult Edit(int id)
        {
            // Get movie with the passed id from database
            TVProgram tvprogram = _context.TVPrograms.Include("Owner").SingleOrDefault(m => m.Id == id);

            // If there is acctually a matching entry
            // in the database
            if (tvprogram != null)
            {
                // Get the current logged in user id
                string userId = User.Identity.GetUserId();
                if (tvprogram.Owner.Id == userId)
                {
                    // If the owner id of the tv program equals
                    // the current user id, then this is the
                    // owner and send the user to the edit
                    // form along with the data of the chosen
                    // movie
                    return(View("TVProgramForm", tvprogram));
                }
            }

            // If not the owner of the requested
            // tv program, then redirect to the index
            // action of TVProgram controller
            return(RedirectToAction("Index"));
        }
        public static TVProgram ToTVProgram(this XElement element)
        {
            var rating     = element.Descendants("rating").FirstOrDefault();
            var starRating = element.Descendants("star-rating").FirstOrDefault();

            var result = new TVProgram
            {
                PartitionKey = element.Attribute("start").Value.ParseDate().ToString("yyyyMMdd"),

                Channel         = element.Attribute("channel").Value,
                Start           = element.Attribute("start").Value.ParseDate(),
                Stop            = element.Attribute("stop").Value.ParseDate(),
                Title           = element.Descendants("title").FirstOrDefault()?.Value,
                Description     = element.Descendants("desc").FirstOrDefault()?.Value,
                Category        = element.Descendants("category").FirstOrDefault()?.Value,
                IconSrc         = element.Descendants("icon").FirstOrDefault()?.Attribute("src")?.Value,
                Rating          = rating?.Descendants("value").FirstOrDefault()?.Value,
                RatingIconSrc   = rating?.Descendants("icon").FirstOrDefault()?.Attribute("src").Value,
                StarRating      = starRating?.Descendants("value").FirstOrDefault()?.Value?.Split("/")?.First(),
                LengthInMinutes = Int32.Parse(element.Descendants("length").FirstOrDefault().Value)
            };

            result.RowKey = BitConverter.ToString(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(result.Title + result.Start + result.Stop)));

            return(result);
        }
Ejemplo n.º 6
0
        public ActionResult DeleteConfirmed(int id)
        {
            TVProgram tVProgram = db.TVPrograms.Find(id);

            db.TVPrograms.Remove(tVProgram);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 7
0
 public ActionResult Edit([Bind(Include = "Id,Name,Network,Premiere,ShowDay,ShowTime,Rating,Expressions,Viewership,Duration,Surcharge,Cost")] TVProgram tVProgram)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tVProgram).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tVProgram));
 }
Ejemplo n.º 8
0
        public async Task <IActionResult> PostTVProgram([FromBody] TVProgram tVProgram)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.TVProgram.Add(tVProgram);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTVProgram", new { id = tVProgram.Id }, tVProgram));
        }
Ejemplo n.º 9
0
        private void Bind()
        {
            //查询条件
            GetSearchItem();

            int       totalRecords = 0;
            TVProgram bll          = new TVProgram();

            rpData.DataSource = bll.GetTable(pageIndex, pageSize, out totalRecords, sqlWhere, parms == null ? null : parms.ToArray());
            rpData.DataBind();

            myDataAppend.Append("<div id=\"myDataForPage\" style=\"display:none;\">[{\"PageIndex\":\"" + pageIndex + "\",\"PageSize\":\"" + pageSize + "\",\"TotalRecord\":\"" + totalRecords + "\",\"QueryStr\":\"" + queryStr + "\"}]</div>");
        }
        public ActionResult New()
        {
            // Create a new tv program instance with
            // the current user as the owner (helps
            // when submitting the form)
            string    userId = User.Identity.GetUserId();
            TVProgram model  = new TVProgram()
            {
                Owner = _context.Users.FirstOrDefault(x => x.Id == userId)
            };

            return(View("TVProgramForm", model));
        }
Ejemplo n.º 11
0
        // GET: TVPrograms/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TVProgram tVProgram = db.TVPrograms.Find(id);

            if (tVProgram == null)
            {
                return(HttpNotFound());
            }
            return(View(tVProgram));
        }
Ejemplo n.º 12
0
        public override IEnumerable <object> Solve(TextReader inputStream)
        {
            var nc           = inputStream.ReadIntArray();
            var programCount = nc[0];
            var channels     = nc[1];

            var programs = Enumerable.Repeat(0, channels).Select(_ => new List <TVProgram>()).ToArray();

            for (int i = 0; i < programCount; i++)
            {
                var stc     = inputStream.ReadIntArray();
                var program = new TVProgram(stc[0], stc[1]);
                var channel = stc[2] - 1;
                programs[channel].Add(program);
            }

            var usedDecks = new int[100001];

            for (int channel = 0; channel < programs.Length; channel++)
            {
                var channelPrograms = programs[channel];
                channelPrograms.Sort();
                for (int prog = 0; prog < channelPrograms.Count; prog++)
                {
                    var hasPrevious = prog > 0 && channelPrograms[prog - 1].EndTime == channelPrograms[prog].StartTime;
                    if (hasPrevious)
                    {
                        usedDecks[channelPrograms[prog].StartTime]++;
                    }
                    else
                    {
                        usedDecks[channelPrograms[prog].StartTime - 1]++;
                    }

                    usedDecks[channelPrograms[prog].EndTime]--;
                }
            }

            for (int time = 0; time + 1 < usedDecks.Length; time++)
            {
                usedDecks[time + 1] += usedDecks[time];
            }

            yield return(usedDecks.Max());
        }
        // GET: /TVProgram/Delete/<id>
        public ActionResult Delete(int id)
        {
            // Get the tv program with the passed id from database
            TVProgram tvprogramToDelete = _context.TVPrograms.SingleOrDefault(m => m.Id == id);

            // If there is acctually a matching entry
            // in the database
            if (tvprogramToDelete != null)
            {
                // Delete it from the database
                _context.TVPrograms.Remove(tvprogramToDelete);
                // And save changes
                _context.SaveChanges();
            }

            // Redirect to the Index action of TVProgram controller
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            // TV Station
            TVstation Station = new TVstation();

            Station.Navn = "TV2";
            Station.URL  = "http://www.tv2.dk";

            // Nyt program
            TVProgram Program = new TVProgram();

            Program.Titel          = "Festen";
            Program.StartTidspunkt = new DateTime(2016, 12, 24, 14, 30, 0);
            Program.Station        = Station;

            // Hvad er oprettet?
            Console.WriteLine(Program.Udskriv());

            // Find URL på station
            Console.WriteLine();
            Console.WriteLine("Url på " + Program.Station.Navn + " er " + Program.Station.URL);
            Console.ReadLine();
        }
        public ActionResult Save(TVProgram model)
        {
            if (!ModelState.IsValid)
            {
                // Return to the same form if the data
                // is not valid
                return(View("TVProgramForm", model));
            }

            // Set the owner of this tv program to
            // the current logged in user
            string userId = User.Identity.GetUserId();

            model.Owner = _context.Users.FirstOrDefault(x => x.Id == userId);

            // If the model id is 0, then this is a new one
            // because the id of type "int", which has 0 as
            // its default value
            if (model.Id == 0)
            {
                // Add the new movie to the database
                _context.TVPrograms.Add(model);
            }
            else
            {
                // Else, this is an editing case
                TVProgram tvprogramFromDB = _context.TVPrograms.Single(m => m.Id == model.Id);
                tvprogramFromDB.Name        = model.Name;
                tvprogramFromDB.Description = model.Description;
            }
            // Save changes to database
            _context.SaveChanges();

            // Redirect to the Index action of TVProgram controller
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            int[]     intArray = new int[] { 1, 2, 3, 4, 5 };
            Set <int> intSet   = new Set <int>(intArray);

            intSet.LookUp();
            intSet.Delete(2);
            intSet.LookUp();
            intSet.Add(10);
            intSet.Sort();
            intSet.LookUp();
            float[]     floatArray = new float[] { 1.2f, 2.4f, 3.6f, 4.2f, 5.56f };
            Set <float> floatSet   = new Set <float>(floatArray);

            floatSet.LookUp();
            floatSet.Delete(2);
            floatSet.LookUp();
            floatSet.Add(10);
            floatSet.Sort();
            floatSet.LookUp();
            News        newsObj  = new News("Russia Today", 70, "Новости о России сегодня", "Россия");
            FeatureFilm ffObj    = new FeatureFilm("Interstellar", 250, "Фильм про космос и черные дыры", 16, "26.10.2014", "Matthew MacConaughey");
            Cartoon     cartObj  = new Cartoon("The Incredibles", 116, "Фильм про суперсемейку", 5, "5.11.2004", "Mr. Incredible");
            Cartoon     cartObj2 = new Cartoon("Shrek 2", 105, "Фильм про огра", 5, "19.5.2004", "Shrek");

            TVProgram[]     tvArr = new TVProgram[] { newsObj, ffObj, cartObj, cartObj2 };
            Set <TVProgram> tvSet = new Set <TVProgram>(tvArr);

            tvSet.LookUp();
            tvSet.Delete(ffObj);
            tvSet.LookUp();
            tvSet.Add(newsObj);
            tvSet.Sort();
            tvSet.LookUp();
            tvSet.ToFile(@"D:\BSTU stuff\3 семестр 2 курс\ООП\C_Sharp\Лаб. 8\new.txt");
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            News        newsObj  = new News("Russia Today", 70, "Новости о России сегодня", "Россия");
            FeatureFilm ffObj    = new FeatureFilm("Interstellar", 250, "Фильм про космос и черные дыры", 16, "26.10.2014", "Matthew MacConaughey");
            Cartoon     cartObj  = new Cartoon("The Incredibles", 116, "Фильм про суперсемейку", 5, "5.11.2004", "Mr. Incredible");
            Cartoon     cartObj2 = new Cartoon("Shrek 2", 105, "Фильм про огра", 5, "19.5.2004", "Shrek");

            newsObj.TurnOn();
            newsObj.VolumeUp();
            Console.WriteLine(newsObj.ToString());

            TVProgram prog = new Cartoon("Смешарики", 40, "Фильм про существ круглого цвета", 2, "2.12.2012", "Крош И Ёжик");

            Console.WriteLine(prog.ToString());

            Console.WriteLine(prog is TVProgram ? "Объект prog есть класс TVProgram" : "Объект prog не есть класс TVProgram");
            Console.WriteLine(newsObj is Film ? "Объект newsObj есть класс Film" : "Объект newsObj не есть класс Film");

            var cartProg = prog as Cartoon;

            if (cartProg != null)
            {
                Console.WriteLine(cartProg.ToString());
            }

            ffObj.Direct();
            ffObj.ShowAd();
            cartObj.ShowAd();
            cartObj.ShowAd();

            Printer prt = new Printer();

            TVProgram[] array = new TVProgram[] { cartObj, newsObj, ffObj };
            foreach (var el in array)
            {
                prt.IAmPrinting(el);
                Console.WriteLine();
            }

            Console.WriteLine("~~~~~~~~~~~~~~~~~~~~Лабораторная 6~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            Logger logger = new Logger();

            Console.WriteLine(cartObj.relDate.GetDate());
            ProgramGuide pg = new ProgramGuide();

            pg.AddProgram(cartObj);
            pg.AddProgram(ffObj);
            pg.AddProgram(cartObj2);
            pg.ShowProgramGuide();
            ProgramGuideControler.FindSameYear(pg, 2004);
            ProgramGuideControler.ProgramGuideDuration(pg);
            ProgramGuideControler.ProgramGuideAdAmount(pg);
            Console.WriteLine();

            //Чтение текстового файла
            string             path          = @"D:\BSTU stuff\3 семестр 2 курс\ООП\C_Sharp\Лаб. 6\lab6.txt";
            List <FeatureFilm> newCollection = ProgramGuideControler.ReadFile(path);

            foreach (var el in newCollection)
            {
                Console.WriteLine(el.ToString() + "\n|\nV");
            }
            //Чтение json файла

            string path2 = @"D:\BSTU stuff\3 семестр 2 курс\ООП\C_Sharp\Лаб. 6\lab6json.txt";

            try
            {
                newCollection = ProgramGuideControler.ReadJson(path2);
                foreach (var el in newCollection)
                {
                    Console.WriteLine(el.ToString() + "\n|\nV");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                logger.AddLog(e);
            }

            ///////////////////////////////Лаб. 7////////////////////////

            int[] arrayExc = new int[5] {
                1, 2, 3, 4, 5
            };
            Console.WriteLine("Введите элемент массива, к которому хотите получить доступ");
            int index;

            try
            {
                if (!Int32.TryParse(Console.ReadLine(), out index))
                {
                    throw new WrongInputException("Введен не целое число!");
                }
                try
                {
                    if (index >= arrayExc.Length && index <= 0)
                    {
                        throw new IndexOutOfRangeException("Введен неверный индекс!");
                    }
                    Console.WriteLine(arrayExc[index]);
                }
                catch (IndexOutOfRangeException ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.AddLog(ex);
                }
            }
            catch (WrongInputException e)
            {
                Console.WriteLine(e.Message);
                logger.AddLog(e);
            }

            Console.WriteLine("Введите делимое и делитель, чтобы произвести деление");
            int firstInt  = Convert.ToInt32(Console.ReadLine());
            int secondInt = Convert.ToInt32(Console.ReadLine());

            try
            {
                if (secondInt == 0)
                {
                    throw new DivideByZeroException("Делитель не должен быть равен 0!");
                }
                Console.WriteLine(firstInt / secondInt);
            }
            catch (DivideByZeroException ex)
            {
                Console.WriteLine(ex.Message);
                logger.AddLog(ex);
            }
            Console.WriteLine(logger.ToString());
            string path3 = @"D:\BSTU stuff\3 семестр 2 курс\ООП\C_Sharp\Лаб. 6\log.txt";

            logger.ToFile(path3);
            Debug.Assert(false, "Конец программы");
        }