Ejemplo n.º 1
0
        public IActionResult Create(ViewModelCreateUrl newLink)
        {
            if (newLink is null)
            {
                throw new ArgumentNullException(nameof(newLink));
            }

            if (!ModelState.IsValid)
            {
                return(View(newLink));
            }

            var id = newLink.Id;

            if (_urlDisplayer.GetById(id) == null)
            {
                _urlDisplayer.Add(newLink);
            }
            else
            {
                throw new Exception("Эта ссылка уже была добавлена");
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public void Add(ViewModelCreateUrl ViewUrlEntity)
        {
            UrlConvertor convertor = new UrlConvertor(ViewUrlEntity);
            convertor.GetUrls();

            var urlEntity = _mapper.Map<UrlEntity>(ViewUrlEntity);

            UrlComplete dateLink = new UrlComplete(urlEntity);
            var urlComplete = dateLink.GetWholeUrl();

            urlComplete.Id = _db.stringUrl.Count() == 0 ? 1 : _db.stringUrl.Max(c => c.Id) + 1;

            _db.stringUrl.Add(urlComplete);
            SaveChanges();
        }
Ejemplo n.º 3
0
 public UrlConvertor(ViewModelCreateUrl url)
 {
     _url = url;
 }