コード例 #1
0
        public static void Update(this InformationBlock item, InformationBlockModel m)
        {
            switch (item)
            {
            case TextInformationBlock bl:
            {
                var b = (TextInformationBlockModel)m;

                bl.Text = b.Text;

                break;
            }

            case ImageInformationBlock bl:
            {
                var b = (ImageInformationBlockModel)m;

                // TODO image

                break;
            }

            case VideoInformationBlock bl:
            {
                var b = (VideoInformationBlockModel)m;

                bl.Url = b.Url;

                break;
            }
            }

            item.SequentialNumber = m.SequentialNumber;
        }
コード例 #2
0
        public static InformationBlock ToEntity(this InformationBlockModel block)
        {
            InformationBlock model;

            // TODO image block file id
            switch (block)
            {
            case TextInformationBlockModel bl:
                model = new TextInformationBlock
                {
                    Text = bl.Text
                };
                break;

            case VideoInformationBlockModel bl:
                model = new VideoInformationBlock
                {
                    Url = bl.Url
                };
                break;

            case ImageInformationBlockModel _:
                model = new ImageInformationBlock();
                break;

            default:
                model = new InformationBlock();
                break;
            }

            model.SequentialNumber = block.SequentialNumber;
            return(model);
        }
コード例 #3
0
 public ActionResult RenderInformationBlock(int?informationBlockId = null)
 {
     try
     {
         InformationBlockModel model = new InformationBlockModel();
         if (informationBlockId != null)
         {
             InformationBlock informationBlock =
                 DatabaseContext.InformationBlocks.FirstOrDefault(b => b.Id == informationBlockId);
             if (informationBlock == null)
             {
                 throw new ArgumentException("Выбранной новости не найдено");
             }
             string informationBlockPath = "\\InformationBlock_" + informationBlockId;
             IEnumerable <string> informationBlockFiles = GetFilesNames(informationBlockPath);
             model.Id    = informationBlock.Id;
             model.Title = informationBlock.Title;
             model.Body  = informationBlock.Body;
             model.Files = informationBlockFiles;
             model.Date  = informationBlock.Date.ToString("g");
             IEnumerable <Tag> tags = DatabaseContext.Tags.ToList();
             model.Tags = tags.Select(t =>
             {
                 return(new SelectListItem()
                 {
                     Text = t.Name,
                     Value = t.Id.ToString(),
                     Selected = informationBlock.TagInformationBlocks.FirstOrDefault(b => b.TagId == t.Id) != null
                 });
             });
             model.TagsIds = tags.Where(t =>
                                        informationBlock.TagInformationBlocks.FirstOrDefault(b => b.TagId == t.Id) != null)
                             .Select(t => t.Id.ToString());
         }
         else
         {
             IEnumerable <Tag> tags = DatabaseContext.Tags.ToList();
             model.Tags = tags.Select(t =>
             {
                 return(new SelectListItem()
                 {
                     Text = t.Name,
                     Value = t.Id.ToString(),
                     Selected = false
                 });
             });
         }
         return(PartialView("_CreateEditInformationBlock", model));
     }
     catch (Exception e)
     {
         Logger.Error(e.Message);
         return(new HttpNotFoundResult());
     }
 }
コード例 #4
0
        public static InformationBlockModel ToDto(this InformationBlock b)
        {
            InformationBlockModel dto;

            switch (b)
            {
            case TextInformationBlock bl:
                dto = new TextInformationBlockModel
                {
                    Text = bl.Text
                };
                break;

            case VideoInformationBlock bl:
                dto = new VideoInformationBlockModel
                {
                    Url = bl.Url
                };
                break;

            case ImageInformationBlock bl:
                dto = new ImageInformationBlockModel
                {
                    Name = bl.FileId.ToString()
                };
                break;

            default:
                dto = new InformationBlockModel();
                break;
            }

            dto.SequentialNumber = b.SequentialNumber;
            dto.Id = b.Id;
            return(dto);
        }
コード例 #5
0
//        [HttpPost]
        public async Task <IActionResult> Test3(/*[FromBody] */ InformationBlockModel m)
        {
            return(Json(m));
        }