public int AddURL(URLModel url, string host, int port, string sessionUserId) { int lastId; UrlRepository.Add(url); if (!UrlIsValid(url.LongURL)) { url.LongURL = "http://" + url.LongURL; } SaveURL(); lastId = AddShortenedURLToLast(host, port); SaveURL(); if (!string.IsNullOrEmpty(sessionUserId)) { var tmpUserID = Convert.ToInt32(sessionUserId); var userFoundById = UserRepository.GetWhere(x => x.Id == tmpUserID).FirstOrDefault(); UserRepository.Update(userFoundById); userFoundById.URLs.Add(url); UnitOfWork.Commit(); } return(lastId); }