private UnitOfMeasure GetUnitOfMeasure(UnitOfMeasure request) { var id = request?.Id; UnitOfMeasure ret = null; var query = DocQuery.ActiveQuery ?? Execute; DocPermissionFactory.SetSelect <UnitOfMeasure>(currentUser, "UnitOfMeasure", request.Select); DocEntityUnitOfMeasure entity = null; if (id.HasValue) { entity = DocEntityUnitOfMeasure.Get(id.Value); } if (null == entity) { throw new HttpError(HttpStatusCode.NotFound, $"No UnitOfMeasure 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 UnitOfMeasure Post(UnitOfMeasureCopy request) { UnitOfMeasure ret = null; using (Execute) { Execute.Run(ssn => { var entity = DocEntityUnitOfMeasure.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 pIsSI = entity.IsSI; var pName = entity.Name; var pType = entity.Type; var pUnit = entity.Unit; var copy = new DocEntityUnitOfMeasure(ssn) { Hash = Guid.NewGuid() , IsSI = pIsSI , Name = pName , Type = pType , Unit = pUnit }; copy.SaveChanges(DocConstantPermission.ADD); ret = copy.ToDto(); }); } return(ret); }