public async Task <ActionResult <Tag> > Put(string tag)
        {
            var e = new Tag(tag);
            await _repo.AddTag(e);

            return(Ok(e));
        }
        public ActionResult Create(Tag tag)
        {
            try
            {
                List <Tag> tags = _tagRepo.GetAllTags();
                //check for duplicate tags
                foreach (Tag t in tags)
                {
                    if (t.Name.ToLower() == tag.Name.ToLower().Trim())
                    {
                        throw new Exception();
                    }
                }

                //title case tag name
                TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
                tag.Name = textInfo.ToTitleCase(tag.Name);

                _tagRepo.AddTag(tag);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                tag.ErrorMessage = "A tag with that name already exists!";
                return(View(tag));
            }
        }
Exemple #3
0
 public void AddTag(Tag tag)
 {
     if (_context.Tags.Any(t => t.Name.ToLower() == tag.Name.Trim().ToLower()))
     {
         throw new Exception($"Тег {tag.Name} уже есть в базе");
     }
     _tagRepository.AddTag(tag);
 }
        public ActionResult Add(News news, int CategoryId, HttpPostedFileBase ShowcasePicture, IEnumerable <HttpPostedFileBase> DetailPicture, string Tag)
        {
            var  sessionControl = HttpContext.Session["UserId"];
            User user           = _userRepository.Get(x => x.Id == (int)sessionControl);

            news.UserId     = user.Id;
            news.CategoryId = CategoryId;
            if (ShowcasePicture != null)
            {
                string file      = Guid.NewGuid().ToString().Replace("-", "");
                string extension = System.IO.Path.GetExtension(Request.Files[0].FileName);
                string path      = uploadpathNews + file + extension;
                Request.Files[0].SaveAs(path);
                news.ShowcasePicture = path;
            }
            _newsRepository.Insert(news);
            _newsRepository.Save();

            _tagRepository.AddTag(news.Id, Tag);

            string multiplePicture = System.IO.Path.GetExtension(Request.Files[1].FileName);

            if (multiplePicture != "")
            {
                foreach (var file in DetailPicture)
                {
                    if (file.ContentLength > 0)
                    {
                        string fileName      = Guid.NewGuid().ToString().Replace("-", "");
                        string fileExtension = System.IO.Path.GetExtension(Request.Files[1].FileName);
                        string filePath      = uploadpathNews + fileName + fileExtension;
                        file.SaveAs(filePath);
                        var image = new Picture
                        {
                            PictureUrl = filePath
                        };
                        image.NewsId = news.Id;
                        _pictureRepository.Insert(image);
                        _pictureRepository.Save();
                    }
                }
            }
            TempData["Message"] = "Haber ekleme işleminiz başarılı";
            return(RedirectToAction("Index", "News"));
        }
Exemple #5
0
        public async Task <ActionResult> AddTag(PostTagDto dto, CancellationToken cancellationToken)
        {
            if (await _tagRepository.AddTag(dto, cancellationToken))
            {
                return(Ok("با موفقیت ایجاد شد"));
            }

            return(BadRequest("خطا در ثبت تگ"));
        }
        public ActionResult Add(News news, HttpPostedFileBase ImageVit, IEnumerable <HttpPostedFileBase> ImageList, string tag)
        {
            var sessionControl = HttpContext.Session["AppUserEmail"];

            if (news == null)
            {
                throw new NullReferenceException();
            }
            else
            {
                if (ImageVit != null)
                {
                    string fileName   = Guid.NewGuid().ToString().Replace("-", "");
                    string extensionn = System.IO.Path.GetExtension(Request.Files[0].FileName);
                    string fullPath   = "/Content/External/NewsPic/" + fileName + extensionn;
                    Request.Files[0].SaveAs(Server.MapPath(fullPath));
                    news.Image = fullPath;
                }
                AppUser appUser = _appUserRepository.GetByEmail(sessionControl.ToString());
                news.UserId = appUser.Id;

                _newsRepository.Insert(news);
                _newsRepository.Save();



                _tagRepository.AddTag(news.Id, tag);

                string ListOfPic = System.IO.Path.GetExtension(Request.Files[1].FileName);
                if (ImageList != null)
                {
                    foreach (var pic in ImageList)
                    {
                        string fileName   = Guid.NewGuid().ToString().Replace("-", "");
                        string extensionn = System.IO.Path.GetExtension(Request.Files[0].FileName);
                        string fullPath   = "/Content/External/NewsPic/" + fileName + extensionn;
                        pic.SaveAs(Server.MapPath(fullPath));

                        Image image = new Image
                        {
                            NewsImage      = fullPath,
                            CreatedTime    = DateTime.Now,
                            IsActived      = true,
                            OnModifiedTime = DateTime.Now
                        };
                        image.NewsId = news.Id;
                        _imageRepository.Insert(image);
                        _imageRepository.Save();
                    }
                }
            }
            TempData["Information"] = "Process of Adding News is Success";
            return(RedirectToAction("Index", "News"));
        }
        public IActionResult Post(Tag tag)
        {
            var currentUserProfile = GetCurrentUserProfile();

            if (currentUserProfile.UserTypeId != 1)
            {
                return(Unauthorized());
            }
            _tagRepository.AddTag(tag);
            return(CreatedAtAction("Get", new { id = tag.Id }, tag));
        }
 public ActionResult Create(Tags tag)
 {
     try
     {
         _tagRepository.AddTag(tag);
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         return(View(tag));
     }
 }
 public ActionResult Create(Tag tag)
 {
     try
     {
         _tagRepository.AddTag(tag);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View(tag));
     }
 }
Exemple #10
0
        public async Task <bool> AddTagToTask(Tag tag, int taskId)
        {
            if (string.IsNullOrEmpty(tag.Text))
            {
                throw new Exception("Tag title can't be empty");
            }
            var tagId = await _tagRepository.AddTag(tag);

            await _tagRepository.AddTagToTask(tagId, taskId);

            return(true);
        }
Exemple #11
0
        /// <summary>
        /// 增加标签
        /// </summary>
        /// <param name="tagModel"></param>
        /// <returns></returns>
        public bool AddTag(string tagName)
        {
            var result = _tagRepsitory.GetTagByTagName(tagName);

            if (result == null)
            {
                return(_tagRepsitory.AddTag(tagName));
            }
            else
            {
                return(false);
            }
        }
Exemple #12
0
        public async Task <JsonResult> AddTag(string tagName)
        {
            var tag = new Tag()
            {
                Name = tagName
            };

            await _tagRepository.AddTag(tag);

            await _context.SaveChangesAsync();

            object data = null;

            return(new JsonResult(new { data, success = true }));
        }
        public ActionResult Create(Tag tag)
        {
            if (!User.IsInRole("1"))
            {
                return(RedirectToAction("Index", "Home"));
            }
            try
            {
                _tagRepository.AddTag(tag);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                return(View(tag));
            }
        }
Exemple #14
0
        public async Task <IActionResult> CreateTag([FromBody] TagResource tagResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var tag = mapper.Map <TagResource, Tag>(tagResource);

            repository.AddTag(tag);

            repository.UpdateTagProjects(tag, tagResource);

            await unitOfWork.Complete();

            tag = await repository.GetTag(tag.TagId);

            var result = mapper.Map <Tag, TagResource>(tag);

            return(Ok(result));
        }
 public IActionResult Create(Tag tag)
 {
     _tagRepository.AddTag(tag);
     return(RedirectToAction("Index"));
 }
 public IActionResult AddTag(Tag tagP)
 {
     repository.AddTag(tagP);
     return(RedirectToAction(nameof(Index)));
 }
 public IActionResult AddTag(Tag tag)
 {
     _tagRepository.AddTag(tag);
     return(CreatedAtAction("Get", new { id = tag.Id }, tag));
 }
Exemple #18
0
        public async Task ProcessJob(Job job)
        {
            if (string.IsNullOrEmpty(job.Url))
            {
                logger.Debug($"Job '{job.Name}' has no URL, ignoring");
                return;
            }

            try
            {
                var html = await httpWrapper.GetPageContent(job.Url);

                var pageParser = new Pageparser(html);

                if (job.Replace)
                {
                    tagRepository.Clear(job.Url);
                }

                if (!string.IsNullOrEmpty(job.Category))
                {
                    tagRepository.AddTag(job.Url, "category", job.Category, job.AccessLevel);
                }

                foreach (var selection in job.Selections)
                {
                    List <string> values;

                    if (selection.Hardcoded)
                    {
                        values = selection.Value.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToList();
                    }
                    else
                    {
                        values = pageParser.GetSelectionValues(selection.SearchPath);
                    }

                    if (!values.Any())
                    {
                        logger.Warn($"Job '{job.Name}' returned no values");
                        continue;
                    }

                    foreach (var value in values)
                    {
                        if (selection.Output == OutputType.Tag)
                        {
                            tagRepository.AddTag(job.Url, selection.TagName, value, job.AccessLevel);
                        }
                        else
                        {
                            string url = value;

                            Uri temp;

                            if (!Uri.TryCreate(url, UriKind.Absolute, out temp))
                            {
                                url = new Uri(new Uri(job.Url), url).ToString();
                            }

                            jobRepository.RegisterAdhocJob(url, selection.JobName);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error($"Job '{job.Name}' failed", ex);
            }
        }