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")); }
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(); }
public UrlConvertor(ViewModelCreateUrl url) { _url = url; }