public IActionResult Post(Link link) { var currentUser = GetCurrentUserProfile(); if (link.CategoryId != null) { var category = _categoryRepository.GetById((int)link.CategoryId); if (category.UserProfileId != currentUser.Id) { return(BadRequest()); } } link.UserProfileId = currentUser.Id; link.CreateDate = DateTime.Now; _linkRepository.Add(link); return(CreatedAtAction("Get", new { id = link.Id }, link)); }
public Link GenerateNewLink(LinkRepository lRepository, int fileId) { if (lRepository != null) { Link l = new Link(); l.FileId = fileId; l.Email = ""; l.Count = 0; l.PublicId = Guid.NewGuid(); while (lRepository.Get(l.PublicId) != null) { l.PublicId = Guid.NewGuid(); } l.Url = "/Files/Download/" + l.PublicId; l.Id = lRepository.Add(l); return(l); } else { return(null); } }