public HttpResponseMessage CreateProjectExternalShare(ProjectExternalShareModel projectExternalShare, int projectId) { if (!ModelState.IsValid || projectId <= 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var identity = User.Identity as ClaimsIdentity; //STEP 1 - Update the project statistic for external share using (var ps = new ProjectStatRepository()) { bool hasUpdatedProjectStat = ps.IncrementProjectStatSharesNo(projectId); //project to update stat not found if (!hasUpdatedProjectStat) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } using (var s = new ProjectExternalShareRepository()) { var httpStatusCode = HttpStatusCode.Created; // STEP 2: Create new external share and save it to database table of external shares bool hasInserted = s.CreateExternalShare(projectExternalShare, identity, projectId); switch (hasInserted) { //project for creating external share not found case false: httpStatusCode = HttpStatusCode.NotFound; break; //external share inserted ok case true: httpStatusCode = HttpStatusCode.Created; break; } return(Request.CreateResponse(httpStatusCode)); } }
public bool CreateExternalShare(ProjectExternalShareModel source, ClaimsIdentity identity, int projectId) { Project _project = uow.ProjectRepository.FindById((long)projectId); if (_project == null) { return(false); } long requestorUserId; try { requestorUserId = uow.UserRepository .SearchFor(e => e.Username == identity.Name) .Select(e => e.Id) .SingleOrDefault(); } catch (InvalidOperationException ex) { throw new InvalidOperationException("User lookup for requestor Id failed in CreateExternalShare", ex); } try { var _projectExternalShare = new ProjectExternalShare() { ProjectId = source.ProjectId, UserId = requestorUserId, Target = source.Target, Source = source.Source, WhenDateTime = DateTime.Now }; uow.ProjectExternalShareRepository.Insert(_projectExternalShare, true); return(true); } catch (Exception) { throw; } }