コード例 #1
0
        public IActionResult Edit(long id)
        {
            ReclameBlock oldBlock = reclameBlockService.Get(id);

            ViewBag.ResponsibleId = new SelectList(employerService.All().OrderBy(e => e.Name), "Id", "Name", oldBlock.ResponsibleId);
            if (oldBlock == null)
            {
                return(RedirectToActionErrMsg(nameof(Index), "ReclameBlock", "Объект не найден"));
            }
            return(View(oldBlock));
        }
コード例 #2
0
        public IActionResult GetAutoReleases(long rbId)
        {
            ReclameBlock block = reclameBlockService.Get(rbId);

            if (block == null)
            {
                return(RedirectToActionErrMsg(nameof(Index), "ReclameBlock", "Объект не найден"));
            }
            if (!block.Status)
            {
                return(RedirectToActionErrMsg(nameof(Index), "ReclameBlock", "Блок не активен"));
            }
            ViewBag.Name = block.Name;
            List <Release> model = releaseService.GetAutoReleases(rbId);

            return(View("Auto", model));
        }
コード例 #3
0
 public IActionResult Edit(ReclameBlock block)
 {
     ViewBag.ResponsibleId = new SelectList(employerService.All().OrderBy(e => e.Name), "Id", "Name", block.ResponsibleId);
     if (ModelState.IsValid)
     {
         int result = reclameBlockService.Edit(setting, block);
         if (result == -2)
         {
             return(RedirectToActionErrMsg(nameof(Index), "ReclameBlock", String.Format("Нельзя создать  ежечасные блоки в количестве более {0}", setting.MaxBlocks)));
         }
         if (result <= 0)
         {
             return(RedirectToActionOkMsg(nameof(Index), "ReclameBlock", "Данные успешно сохранены"));
         }
         else
         {
             return(RedirectToActionErrMsg(nameof(Index), "ReclameBlock", "Ошибка сохранения данных"));
         }
     }
     return(View(block));
 }
コード例 #4
0
ファイル: ReleaseService.cs プロジェクト: yanovich20/RadioGit
        public List <Release> GetAutoReleases(long rbId)
        {
            ReclameBlock rb = reclameBlockRepository.GetWithReleases(rbId);

            if (rb == null)
            {
                return(null);
            }
            List <Release> result = new List <Release>();

            if (rb.Releases.Count == 0)
            {
                return(new List <Release>());
            }
            var countPeriods = 1;

            for (int i = 0; i < numOfReleases;)
            {
                DateTime currentDate = DateTime.Now;
                if (i == 0)
                {
                    foreach (Release rel in rb.Releases)
                    {
                        if (i >= numOfReleases)
                        {
                            break;
                        }
                        Release autoRelease = new Release
                        {
                            Cost           = rel.Cost,
                            Date           = currentDate,
                            Duration       = rel.Duration,
                            LeadingId      = rel.LeadingId,
                            Leading        = rel.Leading,
                            ReclameBlockId = rel.ReclameBlockId,
                            ReclameBlock   = rel.ReclameBlock,
                            State          = State.Planned
                        };
                        if (i == 0)
                        {
                            autoRelease.State = State.OnAir;
                        }
                        result.Add(autoRelease);
                        currentDate = currentDate + rel.Duration;
                        i++;
                    }
                }
                else
                {
                    foreach (Release rel in rb.Releases)
                    {
                        if (i >= numOfReleases)
                        {
                            break;
                        }
                        Release autoRelease = new Release
                        {
                            Cost           = rel.Cost,
                            Duration       = rel.Duration,
                            LeadingId      = rel.LeadingId,
                            Leading        = rel.Leading,
                            ReclameBlockId = rel.ReclameBlockId,
                            ReclameBlock   = rel.ReclameBlock,
                            State          = State.Planned
                        };

                        var date = currentDate;

                        switch (rb.Period)
                        {
                        case Period.Hour:
                            date = date.AddHours(countPeriods);
                            //autoRelease.Date = DateTime.Now.AddHours(countPeriods);
                            break;

                        case Period.Day:
                            date = currentDate.AddDays(countPeriods);
                            //autoRelease.Date = DateTime.Now.AddDays(countPeriods);
                            break;

                        case Period.Week:
                            date = currentDate.AddDays(countPeriods * 7);
                            //autoRelease.Date = DateTime.Now.AddDays(countPeriods * 7);
                            break;
                        }
                        autoRelease.Date = date;
                        result.Add(autoRelease);
                        currentDate = currentDate + rel.Duration;
                        i++;
                    }
                    countPeriods++;
                }
            }
            return(result);
        }