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;
        }
        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);
        }
Exemplo n.º 3
0
 public JsonResult EditInformationBlock(CreateEditInformationBlockModel model)
 {
     try
     {
         InformationBlock informationBlock =
             DatabaseContext.InformationBlocks.FirstOrDefault(b => b.Id == model.Id.Value);
         if (informationBlock == null)
         {
             throw new ArgumentException("Выбранной новости не найдено");
         }
         informationBlock.Title = model.Title;
         informationBlock.Body  = model.Body;
         IEnumerable <int> ids  = model.TagsIds.Select(t => Convert.ToInt32(t));
         IEnumerable <Tag> tags = ids.Select(tagId =>
                                             DatabaseContext.Tags.FirstOrDefault(t => t.Id == tagId));
         List <TagInformationBlock> tagInformationBlocks = tags.Select(t =>
         {
             return(new TagInformationBlock()
             {
                 Tag = t,
                 InformationBlock = informationBlock
             });
         }).ToList();
         informationBlock.TagInformationBlocks = tagInformationBlocks;
         DatabaseContext.SaveChanges();
         if (model.Files != null)
         {
             string        rootDirectory = Server.MapPath("~\\Files");
             string        currentInformationBlockDirectory = "\\InformationBlock_" + informationBlock.Id;
             string        informationBlockDirectoryName    = rootDirectory + currentInformationBlockDirectory;
             DirectoryInfo directory = new DirectoryInfo(informationBlockDirectoryName);
             if (!directory.Exists)
             {
                 directory.Create();
                 informationBlock.File = currentInformationBlockDirectory;
                 DatabaseContext.SaveChanges();
             }
             else
             {
                 foreach (var file in directory.GetFiles())
                 {
                     file.Delete();
                 }
             }
             foreach (var file in model.Files)
             {
                 string fileName = Path.GetFileName(file.FileName);
                 file.SaveAs(directory.FullName + "\\" + fileName);
             }
         }
         return(Json(new { result = true }));
     }
     catch (Exception e)
     {
         Logger.Error(e.Message);
         return(Json(new { result = false }));
     }
 }
Exemplo n.º 4
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());
     }
 }
Exemplo n.º 5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="OptionsReader{TOptions}" /> class.
        /// </summary>
        /// <param name="maxDepth">The maximun depth of the option groups to be searched for.</param>
        /// <param name="name">The parser's name to be used within any exceptions.</param>
        public OptionsReader(int maxDepth, string name)
        {
            this.Name = name;

            _parser = new Parser("DoctranOptions", InformationBlock.MultiDepthEnumeration(1, maxDepth))
            {
                ErrorListener = new ErrorListener <ParserException>(
                    warn => this.ErrorListener.Warning(new OptionReaderException(warn.StartLine, warn.EndLine, warn.Message)),
                    err => this.ErrorListener.Error(new OptionReaderException(err.StartLine, err.EndLine, err.Message)))
            };
        }
Exemplo n.º 6
0
        public JsonResult CreateInformationBlock(CreateEditInformationBlockModel model)
        {
            try
            {
                InformationBlock informationBlock = new InformationBlock()
                {
                    Title    = model.Title,
                    Body     = model.Body,
                    Date     = DateTime.UtcNow,
                    Employee = (CurrentUser as Employee)
                };
                DatabaseContext.InformationBlocks.Add(informationBlock);
                DatabaseContext.SaveChanges();
                IEnumerable <int> ids  = model.TagsIds.Select(t => Convert.ToInt32(t));
                IEnumerable <Tag> tags = ids.Select(tagId =>
                                                    DatabaseContext.Tags.FirstOrDefault(t => t.Id == tagId));
                List <TagInformationBlock> tagInformationBlocks = tags.Select(t =>
                {
                    return(new TagInformationBlock()
                    {
                        Tag = t,
                        InformationBlock = informationBlock
                    });
                }).ToList();
                informationBlock.TagInformationBlocks = tagInformationBlocks;
                DatabaseContext.SaveChanges();
                if (model.Files != null)
                {
                    string        rootDirectory = Server.MapPath("~\\Files");
                    string        currentInformationBlockDirectory = "\\InformationBlock_" + informationBlock.Id;
                    string        informationBlockDirectoryName    = rootDirectory + currentInformationBlockDirectory;
                    DirectoryInfo directory = new DirectoryInfo(informationBlockDirectoryName);
                    if (!directory.Exists)
                    {
                        directory.Create();
                        informationBlock.File = currentInformationBlockDirectory;
                    }

                    foreach (var file in model.Files)
                    {
                        string fileName = Path.GetFileName(file.FileName);
                        file.SaveAs(directory.FullName + "\\" + fileName);
                    }
                }
                return(Json(new { result = true }));
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
                return(Json(new { result = false }));
            }
        }
Exemplo n.º 7
0
 public JsonResult RemoveInformationBlock(int informationBlockId)
 {
     try
     {
         InformationBlock informationBlock =
             DatabaseContext.InformationBlocks.FirstOrDefault(b => b.Id == informationBlockId);
         if (informationBlock == null)
         {
             throw new ArgumentException("Выбранной новости не найдено");
         }
         DatabaseContext.InformationBlocks.Remove(informationBlock);
         DatabaseContext.SaveChanges();
         return(Json(new { result = true }));
     }
     catch (Exception e)
     {
         Logger.Error(e.Message);
         return(Json(new { result = false }));
     }
 }
        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);
        }