public UrlData Post(UrlDataEntryModel entryValue) { if (!Uri.IsWellFormedUriString(entryValue.Url, UriKind.Absolute)) { //throw new HttpRequestException("Bad url"); _notification.AddNotification("Bad url - The url is not valid"); return(null); } UrlData entry = _mapper.Map <UrlData>(entryValue); // if no id -> generate a random one // if id -> check if exist before insert if (string.IsNullOrEmpty(entry.Id)) { entry.Id = IdGenerator.GenerateId(); _context.UrlData.InsertOne(entry); return(entry); } if (_context.UrlData.Find(x => x.Id == entry.Id).Any()) { _notification.AddNotification("Id already exist"); return(null); } _context.UrlData.InsertOne(entry); return(entry); }
public ActionResult Post(UrlDataEntryModel entry) { return(Ok(_service.Post(entry))); }