示例#1
0
        public ActionResult Create([Bind(Include = "DocumentID,Title,Count,Text")] Document document, HttpPostedFileBase imageFile)
        {
            if (ModelState.IsValid)
            {
                if (imageFile != null)
                {
                    string        imageFileName   = Path.GetFileName(imageFile.FileName);
                    string        imageExtension  = Path.GetExtension(imageFile.FileName);
                    List <string> imageExtensions = new List <string>()
                    {
                        ".jpg", ".png"
                    };
                    if (imageExtensions.Contains(imageExtension))
                    {
                        imageFile.SaveAs(Server.MapPath("~/Content/Upload/" + imageFileName));

                        ViewBag.Message = "Файл сохранен";
                    }
                    else
                    {
                        ViewBag.Message = "Ошибка расширения файлов ";
                    }
                }

                //
                string       pattern = @"{{(?<val>.*?)}}";
                RegexOptions options = RegexOptions.Compiled | RegexOptions.Singleline;
                Regex        regex   = new Regex(pattern, options);
                if (document.Text != null)
                {
                    Match match = regex.Match(document.Text);

                    while (match.Success)
                    {
                        if (document.Tags.Any(x => x.Name == match.Groups["val"].Value.Trim()))
                        {
                            match = match.NextMatch();
                        }
                        else
                        {
                            document.Tags.Add(new Tag {
                                Name = match.Groups["val"].Value
                            });
                            match = match.NextMatch();
                        }
                    }
                    //
                }
                db.Create(document);

                return(RedirectToAction("Index"));
            }

            return(View(document));
        }
示例#2
0
 public Doc Create(Doc cliente)
 {
     cliente.CalcularTarifa();
     validator.Validate(cliente);
     return(repository.Create(cliente));
 }