private Update GetUpdate(Update request) { var id = request?.Id; Update ret = null; var query = DocQuery.ActiveQuery ?? Execute; DocPermissionFactory.SetSelect <Update>(currentUser, "Update", request.Select); DocEntityUpdate entity = null; if (id.HasValue) { entity = DocEntityUpdate.Get(id.Value); } if (null == entity) { throw new HttpError(HttpStatusCode.NotFound, $"No Update found for Id {id.Value}"); } if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.VIEW)) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have VIEW permission for this route."); } ret = entity?.ToDto(); return(ret); }
public Update Post(UpdateCopy request) { Update ret = null; using (Execute) { Execute.Run(ssn => { var entity = DocEntityUpdate.Get(request?.Id); if (null == entity) { throw new HttpError(HttpStatusCode.NoContent, "The COPY request did not succeed."); } if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.ADD)) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route."); } var pBody = entity.Body; var pDeliveryStatus = entity.DeliveryStatus; var pEmailAttempts = entity.EmailAttempts; var pEmailSent = entity.EmailSent; var pEvents = entity.Events.ToList(); var pLink = entity.Link; if (!DocTools.IsNullOrEmpty(pLink)) { pLink += " (Copy)"; } var pPriority = entity.Priority; var pRead = entity.Read; var pSlackSent = entity.SlackSent; var pSubject = entity.Subject; if (!DocTools.IsNullOrEmpty(pSubject)) { pSubject += " (Copy)"; } var pTeam = entity.Team; var pUser = entity.User; var copy = new DocEntityUpdate(ssn) { Hash = Guid.NewGuid() , Body = pBody , DeliveryStatus = pDeliveryStatus , EmailAttempts = pEmailAttempts , EmailSent = pEmailSent , Link = pLink , Priority = pPriority , Read = pRead , SlackSent = pSlackSent , Subject = pSubject , Team = pTeam , User = pUser }; foreach (var item in pEvents) { entity.Events.Add(item); } copy.SaveChanges(DocConstantPermission.ADD); ret = copy.ToDto(); }); } return(ret); }